org.scalatest.scalacheck

trait CheckSuite

[source: org/scalatest/scalacheck/CheckSuite.scala]

trait CheckSuite
extends Suite
Trait that contains several “check” methods that can be used to perform ScalaCheck property checks that will be reported as a ScalaTest test failure if ScalaCheck finds a test case for which the property doesn't hold. 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, which 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 asertion-based tests. Here's an example of using ScalaCheck from a ScalaTest suite:
 import org.scalatest.scalacheck.CheckSuite
 import org.scalacheck.Arbitrary._
 import org.scalacheck.Prop._

 class MySuite extends CheckSuite {
   def testConcat() {
     checkProperty(
       (a: List[Int], b: List[Int]) => {
         a.size + b.size == (a ::: b).size
       }
     )
   }
 }
 

The checkProperty method, defined in CheckSuite, 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 as parameters the required test data, which will be generated by ScalaCheck. In this case, the test data is composed of lists of integer 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 values for a and b and test each one, looking for a value for which the property doesn't hold. If the property holds true for every value ScalaCheck tries, checkProperty returns normally. Otherwise, checkProperty will complete abruptly with an AssertionError that contains information including the value that caused the failure.

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

To execute CheckSuites with ScalaTest's Runner, you must include ScalaCheck's jar file on the class path or runpath. This version of CheckSuite was tested with ScalaCheck version 1.1.1.

Author
Bill Venners
Method Summary
def checkProperty [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.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4], implicit a5 : (org.scalacheck.Arb[A5]) => org.scalacheck.Arbitrary[A5], implicit a6 : (org.scalacheck.Arb[A6]) => org.scalacheck.Arbitrary[A6]) : Unit
Convert the passed 6-arg function into a property, and check it.
def checkProperty (p : org.scalacheck.Prop) : Unit
Check a property.
def checkProperty [A1, A2, A3, P](f : (A1, A2, A3) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3]) : Unit
Convert the passed 3-arg function into a property, and check it.
def checkProperty (p : org.scalacheck.Prop, prms : org.scalacheck.Test.Params) : Unit
Check a property with the given testing parameters.
def checkProperty [A1, A2, A3, A4, A5, P](f : (A1, A2, A3, A4, A5) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4], implicit a5 : (org.scalacheck.Arb[A5]) => org.scalacheck.Arbitrary[A5]) : Unit
Convert the passed 5-arg function into a property, and check it.
def checkProperty [A1, A2, A3, A4, P](f : (A1, A2, A3, A4) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4]) : Unit
Convert the passed 4-arg function into a property, and check it.
def checkProperty [A1, P](f : (A1) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1]) : Unit
Convert the passed 1-arg function into a property, and check it.
def checkProperty [A1, A2, P](f : (A1, A2) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2]) : Unit
Convert the passed 2-arg function into a property, and check it.
Methods inherited from Suite
nestedSuites, execute, execute, groups, testNames, runTest, runTests, execute, runNestedSuites, suiteName, expectedTestCount, fail, fail, fail, fail, assert, assert, assert, assert, convertToEqualizer, intercept, intercept, expect, expect
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 checkProperty[A1, P](f : (A1) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty[A1, A2, P](f : (A1, A2) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty[A1, A2, A3, P](f : (A1, A2, A3) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty[A1, A2, A3, A4, P](f : (A1, A2, A3, A4) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty[A1, A2, A3, A4, A5, P](f : (A1, A2, A3, A4, A5) => P)(implicit p : (P) => org.scalacheck.Prop, implicit a1 : (org.scalacheck.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4], implicit a5 : (org.scalacheck.Arb[A5]) => org.scalacheck.Arbitrary[A5]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty[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.Arb[A1]) => org.scalacheck.Arbitrary[A1], implicit a2 : (org.scalacheck.Arb[A2]) => org.scalacheck.Arbitrary[A2], implicit a3 : (org.scalacheck.Arb[A3]) => org.scalacheck.Arbitrary[A3], implicit a4 : (org.scalacheck.Arb[A4]) => org.scalacheck.Arbitrary[A4], implicit a5 : (org.scalacheck.Arb[A5]) => org.scalacheck.Arbitrary[A5], implicit a6 : (org.scalacheck.Arb[A6]) => org.scalacheck.Arbitrary[A6]) : 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
AssertionError - if a test case is discovered for which the property doesn't hold.

def checkProperty(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
AssertionError - if a test case is discovered for which the property doesn't hold.

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


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