我正在使用junit 4.12
,jmockit 1.19
& spring-test 4.1.1.RELEASE
来测试我的Spring MVC Java项目。在我pom.xml
这些依赖的JMockit未正确初始化
订单:
jmockit
junit
spring-test
测试用例为服务层是工作的罚款。我只用于测试控制器的弹簧测试。在测试控制器,我得到了以下错误:
java.lang.IllegalStateException: JMockit wasn't properly initialized; please ensure that jmockit precedes junit in the runtime classpath, or use @RunWith(JMockit.class)
对于服务层,我通过在测试类使用@RunWith(JMockit.class)
解决了这个错误。
但是对于控制器我需要用@RunWith(SpringJUnit4ClassRunner.class)
进行注释。
如何解决此错误?
注:我把jmockit
junit
前pom.xml
如果您可以升级到Spring Framework 4.2.1,现在有一流的JUnit _Rules_支持。所以你不需要'SpringJUnit4ClassRunner':http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-junit4-rules –
我相信你将需要显示一个示例测试类和一个重现问题的示例pom.xml文件。我已经测试了这个工具组合(jmockit,junit和spring-test),但没有发现初始化失败。 –