测试使用scalatest无法编译

问题描述 投票:1回答: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>
scala scalatest scalacheck property-based-testing
1个回答
3
投票

除了scalacheck之外,您还需要为scalatest添加依赖项:

<dependency>
    <groupId>org.scalacheck</groupId>
    <artifactId>scalacheck_2.12</artifactId>
    <scope>test</scope>
    <version>1.14.0</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.