获取“NoSuchMethodError:org.hamcrest.Matcher.describeMismatch"在 IntelliJ 10.5 中运行测试时 [英] Getting "NoSuchMethodError: org.hamcrest.Matcher.describeMismatch" when running test in IntelliJ 10.5

查看:39
本文介绍了获取“NoSuchMethodError:org.hamcrest.Matcher.describeMismatch"在 IntelliJ 10.5 中运行测试时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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(即它用于 hamcrest.MatcherAssert 的 jar 文件)?AFAICT,我的类路径中唯一的 hamcrest jars 是 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 中运行测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆