我正在使用
但是对于控制器,我需要使用
如何解决此错误?
注意:我在
junit 4.12
,jmockit 1.19
和spring-test 4.1.1.RELEASE
来测试我的Spring MVC Java项目。这些依赖项在我的pom.xml
文件中的顺序如下:
jmockit
junit
spring-test
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)
进行注释。如何解决此错误?
注意:我在
pom.xml
中将jmockit
放在junit
之前。
SpringJUnit4ClassRunner
:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-junit4-rules - Sam Brannen