相关疑难解决方法(0)

在IntelliJ 10.5中运行测试时获取"NoSuchMethodError:org.hamcrest.Matcher.describeMismatch"

我正在使用JUnit-dep 4.10和Hamcrest 1.3.RC2.

我创建了一个自定义匹配器,如下所示:

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 */
    }
}
Run Code Online (Sandbox Code Playgroud)

使用Ant从命令行运行时,它完全正常.但是当从IntelliJ运行时,它失败了:

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)
Run Code Online (Sandbox Code Playgroud)

我的猜测是它使用了错误的hamcrest.MatcherAssert.我如何找到它使用的hamcrest.MatcherAssert(即哪个jar文件用于hamcrest.MatcherAssert)?AFAICT,我班级路径中唯一的火腿罐是1.3.RC2.

IntelliJ IDEA使用它自己的JUnit或Hamcrest副本吗?

如何输出IntelliJ正在使用的运行时CLASSPATH?

java junit intellij-idea hamcrest junit4

222
推荐指数
6
解决办法
10万
查看次数

junit和hamcrest声明

我在4.10使用junit并在1.3处声明了hamcrest-core,在1.3处声明了hamcrest-library.我的问题是在junit 4.10中嵌入的hamcrest-library和hamcrest-core.junit 4.11怎么样?

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

junit hamcrest maven

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

hamcrest ×2

junit ×2

intellij-idea ×1

java ×1

junit4 ×1

maven ×1