我有使用PropertyChecks
特征的样本测试:
import org.scalatest.prop.PropertyChecks
import org.scalatest.{Matchers, PropSpec}
class AppTest extends PropSpec with PropertyChecks with Matchers {
val invalidCombos =
Table(
("str", "val"),
("1", 1)
)
forAll(invalidCombos) { (n: String, d: Int) =>
val i: Int = Integer.parseInt(n)
whenever(n.length != 0) {
i should be(d)
}
}
}
它给出以下错误:
[ERROR] /home/atcvetkov/project/dummy/dummy-scala/src/test/scala/dummy/AppTest.scala:13: error: Symbol 'type org.scalacheck.Gen' is missing from the classpath.
[INFO] This symbol is required by 'value org.scalatest.prop.GeneratorDrivenPropertyChecks.genAndNameA'.
[INFO] Make sure that type Gen is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[INFO] A full rebuild may help if 'GeneratorDrivenPropertyChecks.class' was compiled against an incompatible version of org.scalacheck.
[INFO] forAll(invalidCombos) { (n: String, d: Int) =>
[INFO] ^
[ERROR] one error found
我检查并发现org.scalacheck.Gen
我的类路径中没有。
我使用以下 Maven 依赖项:
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<scope>test</scope>
<version>3.0.5</version>
</dependency>