Eclipse - Shazamcrest - java.lang.NoSuchFieldError:NONE

时间:2014-12-10 22:10:25

标签: java eclipse junit hamcrest

我在Eclipse STS 3.6.3中遇到此错误。从eclipse插件目录中删除hamcrest jar后,我有基本的Hamcrest调用。据我所知,它使用了hamcrest 1.3和JUnit 4.我查看了Run>运行配置> myTest>来源标签>默认值,我从我当地的maven repo看到了hamcrest 1.3 jar。

它使用mvn命令行,但不在eclipse中。

知道这里发生了什么以及我该如何解决?

@Test
public void testShazamcrestMap() throws Exception {
    HashMap<String,String> item = new HashMap<String,String>(); 
    HashMap<String,String> item2 = new HashMap<String,String>();

    item.put("foo", "bar");
    item2.put("foo", "bar");

    assertThat(item, sameBeanAs(item2));
}
  

java.lang.NoSuchFieldError:NONE       在org.hamcrest.DiagnosingMatcher.matches(DiagnosingMatcher.java:12)       在com.shazam.shazamcrest.MatcherAssert.assertThat(MatcherAssert.java:40)       在com.shazam.shazamcrest.MatcherAssert.assertThat(MatcherAssert.java:29)       在com.nick.feed.test.SomeUnitTest.testShazamcrestMap(SomeUnitTest.java:49)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)       在java.lang.reflect.Method.invoke(Method.java:597)       在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)       在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)       在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)       在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)       在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)       在org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)       在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)       在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)       在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:193)       在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:52)       在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)       在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:42)       在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:184)       在org.junit.runners.ParentRunner.run(ParentRunner.java:236)       在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)       在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

1 个答案:

答案 0 :(得分:2)

我从IntelliJ成功运行了此测试。

我的环境:junit-4.12,hamcrest-1.3,shazamcrest-0.9

确保您只有一个可能的Hamcrest依赖项。较早版本的Junit是导致Hamcrest问题的原因。

Junit 4.10和之前实际上已经嵌入了Hamcrest(除了具有Maven依赖性)。如果必须使用Junit 4.10或之前的版本,请使用不包含Hamcrest的junit-dep。我建议更新到Junit 4.12

您正在使用的Eclipse版本也可能包括通过Junit的Hamcrest。如果是这种情况,Google会将其删除。