Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JMock-java.lang.NoSuchMethodError:org.hamcrest.Matcher.DescribeMatch()_Java_Jmock_Hamcrest - Fatal编程技术网

JMock-java.lang.NoSuchMethodError:org.hamcrest.Matcher.DescribeMatch()

JMock-java.lang.NoSuchMethodError:org.hamcrest.Matcher.DescribeMatch(),java,jmock,hamcrest,Java,Jmock,Hamcrest,我知道解决方案是以某种方式确保在hamcrest之后加载Junit。我有一个intellij项目,在其中我设置了一个外部库,其中包含JUnit、JMock和hamcrest。如何确保此错误不会出现您应该确保库(JAR)的兼容性。如果jar中的一个类使用另一个jar中的类中的某个方法,并且这个使用的方法是新添加的,并且您使用的是旧jar,那么您肯定会得到java.lang.NoSuchMethodError您需要导入junit-dep.jar(不包括hamcrest依赖项!?),而不是junit.

我知道解决方案是以某种方式确保在hamcrest之后加载Junit。我有一个intellij项目,在其中我设置了一个外部库,其中包含JUnit、JMock和hamcrest。如何确保此错误不会出现

您应该确保库(JAR)的兼容性。如果jar中的一个类使用另一个jar中的类中的某个方法,并且这个使用的方法是新添加的,并且您使用的是旧jar,那么您肯定会得到
java.lang.NoSuchMethodError

您需要导入junit-dep.jar(不包括hamcrest依赖项!?),而不是junit.jar。如果您在大型项目中使用Maven,这可能会涉及大量的追踪,以清除所有晦涩难懂的hamcrest和junit导入

即将发布的junit将与hamcrest 1.3兼容,这可能会有所帮助

  • junit:junit:4.11取代了以前的junit:junit-dep
  • JUnit4.11包含org.hamcrest:hamcrest核心:1.3 jar作为依赖项
  • 要在测试中使用显式Hamcrest匹配器,请包括org.Hamcrest:Hamcrest库:1.3
  • mockito:mockito all:1.9.x-包含一个旧版本的Hamcrest,不是作为依赖项,而是包装在它的jar中。这就是罪魁祸首。()
  • 将org.hamcrest:hamcrest core:1.3放在所有测试依赖项之前
  • 使用Maven的DependencyManager部分控制junit、hamcrest和mockito JAR的所有可传递版本。例如,spring集成测试可传递地包括mockito all:1.9.0

  • 您正在使用的外部库是什么?您的项目中是否有junit和/或Hamcrest?