java.lang.IncompatibleClassChangeError:使用ScalaCheck和ScalaTest实现类

时间:2016-02-10 10:19:08

标签: scala scalatest scalacheck

在尝试使用ScalaCheck和ScalaTest编写测试时,我遇到了一个令人讨厌的异常。这是我的依赖:

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "2.2.6" % "test",
  "org.scalacheck" %% "scalacheck" % "1.13.0" % "test"
) 

这是我的测试:

import org.scalatest.PropSpec
import org.scalatest.prop.Checkers

class MyPropSpec extends PropSpec with Checkers {

  property("List.concat") {
    check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size)
  }
}

当我尝试运行时,我得到了:

DeferredAbortedSuite:
 Exception encountered when attempting to run a suite with class name:      org.scalatest.DeferredAbortedSuite *** ABORTED ***
     java.lang.IncompatibleClassChangeError: Implementing class
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
     at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     ...
     java.lang.IncompatibleClassChangeError: Implementing class
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
     at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     ...

我在这里缺少什么?

1 个答案:

答案 0 :(得分:48)

ScalaTest 2.2.6与ScalaCheck 1.13.0不兼容。降级为“scalacheck”%“1.12.5”会有所帮助。

报告为https://github.com/rickynils/scalacheck/issues/217。该问题以下列决议结束:

  

ScalaTest的所有当前版本(2.2.6,3.0.0等)都是针对ScalaCheck 1.12.1构建的(参见https://github.com/scalatest/scalatest/blob/master/project/scalatest.scala#L134)。因此,无法保证您可以简单地将ScalaCheck 1.12.x换成1.13.y. ScalaCheck仅在相同的次要版本系列(1.12.1,1.12.2,1.12.3等)中维护二进制兼容性。