|
ScalaTest 0.9.2
|
|
trait
CheckSuite
extends 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.
| 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
f - the function to be converted into a property and checkedAssertionError - 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
f - the function to be converted into a property and checkedAssertionError - 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
f - the function to be converted into a property and checkedAssertionError - 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
f - the function to be converted into a property and checkedAssertionError - 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
f - the function to be converted into a property and checkedAssertionError - 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
f - the function to be converted into a property and checkedAssertionError - 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
p - the property to checkprms - the test parametersAssertionError - if a test case is discovered for which the property doesn't hold.
def
checkProperty(p : org.scalacheck.Prop) : Unit
p - the property to checkAssertionError - if a test case is discovered for which the property doesn't hold.|
ScalaTest 0.9.2
|
|