1

我有使用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>
4

1 回答 1

3

您还需要添加以下依赖scalacheckscalatest

<dependency>
    <groupId>org.scalacheck</groupId>
    <artifactId>scalacheck_2.12</artifactId>
    <scope>test</scope>
    <version>1.14.0</version>
</dependency>
于 2018-06-12T10:01:49.117 回答