我正在使用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),但沒有發現初始化失敗。 –