Question

I have trouble running my scalachecks from within maven. E.g. the following small snipped

@RunWith(classOf[JUnitRunner])
final class MyTest extends FunSuite with Checkers {
  test("t2") {
    Prop.forAll( (a: String, b: String) => (a+b).startsWith(a) )
  }
}

ends up dumping with the following stack:

java.lang.NoSuchMethodError: scala.runtime.IntRef.zero()Lscala/runtime/IntRef;
    at org.scalacheck.Gen$.frequency(Gen.scala)
    at org.scalacheck.Gen$.chooseNum(Gen.scala:455)
    at org.scalacheck.Arbitrary$$anonfun$arbInt$1.apply(Arbitrary.scala:86)
    at org.scalacheck.Arbitrary$$anonfun$arbInt$1.apply(Arbitrary.scala:86)
    at org.scalacheck.Arbitrary$$anon$2.arbitrary$lzycompute(Arbitrary.scala:65)
    at org.scalacheck.Arbitrary$$anon$2.arbitrary(Arbitrary.scala:65)
    at org.scalacheck.Arbitrary$.arbitrary(Arbitrary.scala:69)
    at org.scalacheck.Arbitrary$$anonfun$arbContainer$1.apply(Arbitrary.scala:299)
    at org.scalacheck.Arbitrary$$anonfun$arbContainer$1.apply(Arbitrary.scala:299)
    at org.scalacheck.Arbitrary$$anon$2.arbitrary$lzycompute(Arbitrary.scala:65)
    at org.scalacheck.Arbitrary$$anon$2.arbitrary(Arbitrary.scala:65)
    at org.scalacheck.Arbitrary$.arbitrary(Arbitrary.scala:69)
    at org.scalacheck.Prop$.forAll(Prop.scala:726)
    at org.scalacheck.Prop$.forAll(Prop.scala:734)

I bet this is only a very small thing to solve but I couldn't find a full example of running scala-check inside scalatest with a junit-runner.

thanks and regards

markus

Was it helpful?

Solution

This worked for me:

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class MyTest extends FunSuite with GeneratorDrivenPropertyChecks {

  test("t2") {
    forAll { (a: String, b: String) =>
      assert((a + b).startsWith(a))
    }
  }
}

Edit

And the dependencies:

scala 2.10.1
scalatest_2.10-1.9.1.jar
scalacheck_2.10-1.10.1.jar
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top