org.scalatest.prop

trait Checkers

[source: org/scalatest/prop/Checkers.scala]

trait Checkers
extends AnyRef
Trait that contains several “check” methods that perform ScalaCheck property checks. If ScalaCheck finds a test case for which a property doesn't hold, the problem will be reported as a ScalaTest test failure.

To use ScalaCheck, you specify properties and, in some cases, generators that generate test data. You need not always create generators, because ScalaCheck provides many default generators for you that can be used in many situations. ScalaCheck will use the generators to generate test data and with that data run tests that check that the property holds. Property-based tests can, therefore, give you a lot more testing for a lot less code than assertion-based tests. Here's an example of using ScalaCheck from a JUnitSuite:

 import org.scalatest.junit.JUnitSuite
 import org.scalatest.prop.Checkers
 import org.scalacheck.Arbitrary._
 import org.scalacheck.Prop._

 class MySuite extends JUnitSuite with Checkers {
   @Test
   def testConcat() {
     check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size)
   }
 }
 

The check method, defined in Checkers, makes it easy to write property-based tests inside ScalaTest, JUnit, and TestNG test suites. This example specifies a property that List's ::: method should obey. ScalaCheck properties are expressed as function values that take the required test data as parameters. ScalaCheck will generate test data using generators and repeatedly pass generated data to the function. In this case, the test data is composed of integer lists named a and b. Inside the body of the function, you see:

 a.size + b.size == (a ::: b).size
 

The property in this case is a Boolean expression that will yield true if the size of the concatenated list is equal to the size of each individual list added together. With this small amount of code, ScalaCheck will generate possibly hundreds of value pairs for a and b and test each pair, looking for a pair of integers for which the property doesn't hold. If the property holds true for every value ScalaCheck tries, check returns normally. Otherwise, check will complete abruptly with a TestFailedException that contains information about the failure, including the values that cause the property to be false.

For more information on using ScalaCheck properties, see the documentation for ScalaCheck, which is available from http://code.google.com/p/scalacheck/.

To execute a suite that mixes in Checkers with ScalaTest's Runner, you must include ScalaCheck's jar file on the class path or runpath. This version of Checkers was tested with ScalaCheck version 1.1.1. This trait must be mixed into a ScalaTest Suite, because its self type is org.scalatest.Suite.

Author
Bill Venners
Method Summary
def check [A1, A2, A3, A4, A5, P](f : (A1, A2, A3, A4, A5) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty, implicit a5 : org.scalacheck.Arbitrary[A5], implicit s5 : org.scalacheck.Shrink[A5], implicit pp5 : (A5) => org.scalacheck.Pretty) : Unit
Convert the passed 5-arg function into a property, and check it.
def check (p : org.scalacheck.Prop) : Unit
Check a property.
def check [A1, A2, A3, P](f : (A1, A2, A3) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty) : Unit
Convert the passed 3-arg function into a property, and check it.
def check [A1, P](f : (A1) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty) : Unit
Convert the passed 1-arg function into a property, and check it.
def check [A1, A2, A3, A4, P](f : (A1, A2, A3, A4) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty) : Unit
Convert the passed 4-arg function into a property, and check it.
def check [A1, A2, P](f : (A1, A2) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty) : Unit
Convert the passed 2-arg function into a property, and check it.
def check [A1, A2, A3, A4, A5, A6, P](f : (A1, A2, A3, A4, A5, A6) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty, implicit a5 : org.scalacheck.Arbitrary[A5], implicit s5 : org.scalacheck.Shrink[A5], implicit pp5 : (A5) => org.scalacheck.Pretty, implicit a6 : org.scalacheck.Arbitrary[A6], implicit s6 : org.scalacheck.Shrink[A6], implicit pp6 : (A6) => org.scalacheck.Pretty) : Unit
Convert the passed 6-arg function into a property, and check it.
def check (p : org.scalacheck.Prop, prms : org.scalacheck.Test.Params) : Unit
Check a property with the given testing parameters.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
def check[A1, P](f : (A1) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty) : Unit
Convert the passed 1-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check[A1, A2, P](f : (A1, A2) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty) : Unit
Convert the passed 2-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check[A1, A2, A3, P](f : (A1, A2, A3) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty) : Unit
Convert the passed 3-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check[A1, A2, A3, A4, P](f : (A1, A2, A3, A4) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty) : Unit
Convert the passed 4-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check[A1, A2, A3, A4, A5, P](f : (A1, A2, A3, A4, A5) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty, implicit a5 : org.scalacheck.Arbitrary[A5], implicit s5 : org.scalacheck.Shrink[A5], implicit pp5 : (A5) => org.scalacheck.Pretty) : Unit
Convert the passed 5-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check[A1, A2, A3, A4, A5, A6, P](f : (A1, A2, A3, A4, A5, A6) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : org.scalacheck.Arbitrary[A1], implicit s1 : org.scalacheck.Shrink[A1], implicit pp1 : (A1) => org.scalacheck.Pretty, implicit a2 : org.scalacheck.Arbitrary[A2], implicit s2 : org.scalacheck.Shrink[A2], implicit pp2 : (A2) => org.scalacheck.Pretty, implicit a3 : org.scalacheck.Arbitrary[A3], implicit s3 : org.scalacheck.Shrink[A3], implicit pp3 : (A3) => org.scalacheck.Pretty, implicit a4 : org.scalacheck.Arbitrary[A4], implicit s4 : org.scalacheck.Shrink[A4], implicit pp4 : (A4) => org.scalacheck.Pretty, implicit a5 : org.scalacheck.Arbitrary[A5], implicit s5 : org.scalacheck.Shrink[A5], implicit pp5 : (A5) => org.scalacheck.Pretty, implicit a6 : org.scalacheck.Arbitrary[A6], implicit s6 : org.scalacheck.Shrink[A6], implicit pp6 : (A6) => org.scalacheck.Pretty) : Unit
Convert the passed 6-arg function into a property, and check it.
Parameters
f - the function to be converted into a property and checked
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check(p : org.scalacheck.Prop, prms : org.scalacheck.Test.Params) : Unit
Check a property with the given testing parameters.
Parameters
p - the property to check
prms - the test parameters
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.

def check(p : org.scalacheck.Prop) : Unit
Check a property.
Parameters
p - the property to check
Throws
TestFailedException - if a test case is discovered for which the property doesn't hold.


Copyright (C) 2001-2010 Artima, Inc. All rights reserved.