代码之家  ›  专栏  ›  技术社区  ›  talex

测试使用scalatest编译失败

  •  1
  • talex  · 技术社区  · 8 年前

    我有样品测试 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>
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   vdebergue    8 年前

    您还需要为 scalacheck 除了 scalatest :

    <dependency>
        <groupId>org.scalacheck</groupId>
        <artifactId>scalacheck_2.12</artifactId>
        <scope>test</scope>
        <version>1.14.0</version>
    </dependency>
    
    推荐文章