Search code examples
scalasbtspecs2

sbt project cannot find ScalaCheck


Using sbt to test the code

package examples
import org.specs2._

class ScalaCheckExamplesSpec extends Specification with ScalaCheck { def is = s2"""
  startsWith ${ prop { (a: String, b: String) => (a+b) must startWith(a) } }
  endsWith   ${ prop { (a: String, b: String) => (a+b) must endWith(b) } }
  substring  ${ prop { (a: String, b: String) => (a+b).substring(a.length) === b } }
  substring  ${ prop { (a: String, b: String, c: String) => (a+b+c).substring(a.length, a.length+b.length) === b } }                                                                                                                       """
}

with sbt configuration:

libraryDependencies ++= Seq(
    "org.specs2" %% "specs2-core" % "3.8.5" % "test",
    "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
)

the class ScalaCheck cannot be found:

ScalaCheckExamplesSpec.scala:11: not found: type ScalaCheck
[error] class ScalaCheckExamplesSpec extends Specification with ScalaCheck {

How can I resolve the error?


Solution

  • You need:

    libraryDependencies ++= Seq(
      "org.specs2" %% "specs2-core" % "3.8.5" % "test",
      // the scalacheck lib will come as a transitive
      // dependency
      "org.specs2" %% "specs2-scalacheck" % "3.8.5" % "test"
    )