Skip to content

Instantly share code, notes, and snippets.

@zenlambda
Last active December 28, 2015 15:19
Show Gist options
  • Save zenlambda/7520515 to your computer and use it in GitHub Desktop.
Save zenlambda/7520515 to your computer and use it in GitHub Desktop.
While working on assignment 2 for the "Reactive Programming with Scala course" I got frustrated with the ScalaCheck library. It's difficult to get it to print out the name of the failing property (in this case "scalatest doc property"). Nor can you seem to print out argument names as the scalatest documentation suggests [1]. http://www.scalatest…
[info] ScalaTestSuite:
[info] - scalatest property test *** FAILED ***
[info] GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info] (ScalaTestSuite.scala:12)
[info] Falsified after 0 successful property evaluations.
[info] Location: (ScalaTestSuite.scala:12)
[info] Occurred when passed generated values (
[info] arg0 = "",
[info] arg1 = ""
[info] )
// failing "scalatest doc property" is not mentioned anywhere in this error!
package simulations
import org.scalacheck.Properties
import org.scalacheck.Prop.forAll
class ScalaCheckProperties extends Properties("Properties from ScalaTest Docs") {
// based on example "supply argument names" property from:
// http://www.scalatest.org/user_guide/generator_driven_property_checks
property("scalatest doc property") = forAll { (a: String, b: String) =>
a.length + b.length == ((a + b).length + 1) // Should fail
}
}
package simulations
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class ScalaTestSuite extends FunSuite with Checkers {
test("scalatest property test") {
check(new ScalaCheckProperties)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment