问题描述
我正在使用JUnit-dep 4.10和Hamcrest 1.3.RC2。
I'm using JUnit-dep 4.10 and Hamcrest 1.3.RC2.
我创建了一个自定义匹配器,如下所示:
I've created a custom matcher that looks like the following:
public static class MyMatcher extends TypeSafeMatcher<String> {
@Override
protected boolean matchesSafely(String s) {
/* implementation */
}
@Override
public void describeTo(Description description) {
/* implementation */
}
@Override
protected void describeMismatchSafely(String item, Description mismatchDescription) {
/* implementation */
}
}
完美无缺使用Ant从命令行运行时。但是当从IntelliJ运行时,它失败了:
It works perfectly fine when run from the command line using Ant. But when run from IntelliJ, it fails with:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at com.netflix.build.MyTest.testmyStuff(MyTest.java:40)
我的猜测是它使用了错误的hamcrest.MatcherAssert。我如何找到它使用的hamcrest.MatcherAssert(即哪个jar文件用于hamcrest.MatcherAssert)? AFAICT,我类路径中唯一的hamcrest jar是1.3.RC2。
My guess is that it's using the wrong hamcrest.MatcherAssert. How do I find which hamcrest.MatcherAssert it's using (ie which jar file it's using for hamcrest.MatcherAssert)? AFAICT, the only hamcrest jars in my classpath is 1.3.RC2.
IntelliJ IDEA是否使用它自己的JUnit或Hamcrest副本?
Is IntelliJ IDEA using it's own copy of JUnit or Hamcrest?
如何输出IntelliJ正在使用的运行时CLASSPATH?
How do I output the runtime CLASSPATH that IntelliJ is using?
推荐答案
问题是错误的 hamcrest.Matcher
,而不是 hamcrest.MatcherAssert
,正在使用类。这是从我的依赖项之一指定的junit-4.8依赖项中提取的。
The problem was that the wrong hamcrest.Matcher
, not hamcrest.MatcherAssert
, class was being used. That was being pulled in from a junit-4.8 dependency one of my dependencies was specifying.
要查看在测试时从哪个源包含哪些依赖项(和版本),请运行:
To see what dependencies (and versions) are included from what source while testing, run:
mvn dependency:tree -Dscope=test
这篇关于获取“NoSuchMethodError:org.hamcrest.Matcher.describeMismatch”在IntelliJ 10.5中运行测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!