I am using junit 4.12
, jmockit 1.19
& spring-test 4.1.1.RELEASE
for testing my Spring MVC Java project.
Order of these dependencies in my pom.xml
:
jmockit
junit
spring-test
Test cases for service layer is working fine. I am using spring-test only for testing controllers. While testing controller, I got the following error:
java.lang.IllegalStateException: JMockit wasn't properly initialized; please ensure that jmockit precedes junit in the runtime classpath, or use @RunWith(JMockit.class)
For service layer, I resolved this error by using @RunWith(JMockit.class )
on test class.
But for controller I need to annotate with @RunWith(SpringJUnit4ClassRunner.class )
.
How to resolve this error?
Note: I put jmockit
before junit
in pom.xml