测试使用scalatest编译失败
Test use scalatest fail to compile
我有使用 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>
除了 scalatest
:
之外,您还需要添加 scalacheck
的依赖
<dependency>
<groupId>org.scalacheck</groupId>
<artifactId>scalacheck_2.12</artifactId>
<scope>test</scope>
<version>1.14.0</version>
</dependency>
我有使用 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>
除了 scalatest
:
scalacheck
的依赖
<dependency>
<groupId>org.scalacheck</groupId>
<artifactId>scalacheck_2.12</artifactId>
<scope>test</scope>
<version>1.14.0</version>
</dependency>