Getting Scalatest and Scalacheck to Work

ScalaTest is a decent library for testing scala code. It integrates with ScalaCheck for "property based testing". In this type of testing, you specify properties of a class or method, and the library generates test cases. I haven't done much property based testing, and it sounds interesting, so I thought I'd give it a shot.

Unfortunately, this two-year-old commit deprecated a ScalaCheck API that is still in use by the current release of ScalaTest. This means that following the instructions on the respective websites for integrating the code into your build.sbt are wrong. So the following will not work:

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.11.3" % "test"

libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0" % "test"

When you try to use certain parts of ScalaTest, you will get this message at compile time:

> test
[info] Compiling 1 Scala source to /home/brian/projects/check/target/scala-2.10/test-classes...
[error] bad symbolic reference. A signature in Configuration.class refers to type Params
[error] in object org.scalacheck.Test which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling Configuration.class.
[error] one error found
[error] (test:compile) Compilation failed

There's an open issue on ScalaTest's github, and there's a snapshot release that works with 1.11.3. Change the scalatest line above to:

libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0.1-SNAP" % "test"

Now reload sbt and the test code should compile cleanly.

Posted on 2014-01-29 by brian in scala .
Comments on this post are closed. If you have something to share, please send me email.