Spock投掷错误我似乎无法理解

时间:2014-10-15 09:17:45

标签: groovy junit spock

  

java.lang.NoClassDefFoundError:   org / junit / internal / AssumptionViolatedException at   org.spockframework.runtime.JUnitSupervisor.error(JUnitSupervisor.java:92)     在   org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:318)     在   org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:297)     在   org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:90)     在   org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:81)     在org.spockframework.runtime.Sputnik.run(Sputnik.java:63)at   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)

我有一个调用方法的简单测试用例

def 'some test for empty Lists'(){
        setup:
        List<Object> clauses=new ArrayList<Object>()

        when:
        String someString=builder.buildString(clauses, "someName", "AND");

        then:
        noExceptionThrown()
        someString==""
    }

假设通过弹簧注入助洗剂。我无法弄清楚为什么会这样。它仅适用于少数测试用例。

非常感谢任何帮助:) 我使用spock 0.6和groovy 1.8。

3 个答案:

答案 0 :(得分:4)

spock 1.0的解决方案,使用jUnit 4.12

只要我将 hamcrest-core-1.3 添加到我的测试类路径中,错误就会消失。

问题是什么?

我观察到问题中描述的相同错误,但我设法 spock 1.0 groovy 2.4 使用 junit-4.12

问题是 junit-4.12 取决于 hamcrest 。 实际上org.junit.internal.AssumptionViolatedException实现了interface org.hamcrest.SelfDescribing

答案 1 :(得分:1)

我使用带有这些版本的简单Eclipse java项目进行spock测试时遇到了同样的错误:

  • 斯波克核-1.0-常规-2.3
  • 的junit-4.12

只有在测试失败的情况下才会抛出异常,但是为成功的

工作了

我发现这是Junit版本的兼容性问题。我使用junit-4.7解决了它,并测试了以下版本:

  • junit-4.6 =&gt;确定
  • junit-4.5 =&gt;确定
  • junit-4.4 =&gt; KO
  • junit-4.0 =&gt; KO

希望有所帮助

答案 2 :(得分:1)

尝试在STS:3.6.4和JBoss Developer Studio版本7.1.1.GA中运行我的spocks时遇到了相同的兼容性问题。

使用junit-4.7代替junit-4.12

解决了问题

其他说明可在https://code.google.com/p/spock/wiki/GettingStarted#Eclipse

找到