@RunWith@ContextConfiguration進行Spring上下文測試報錯

最近在進行Spring的回爐學習在通過 @RunWith和@ContextConfiguration 進行Spring上下文進行測試
具體代碼如下:

@RunWith(SpringRunner.class)
@ContextConfiguration(locations= {"classpath:ioc-helloworld-context.xml"})
public class IocHelloWorldAnnotationTest {
	 @Autowired
	 private  IocHelloWorldXml iocHelloWorldXml;
	 @Autowired
	 private  IocHelloWorldAnnotation iocHelloWorldAnnotation;
	 @Test
	 public void sayXml() {
		 iocHelloWorldXml.say();
	 }
	 
	 @Test
	 public void sayAnnotation() {
		 iocHelloWorldAnnotation.say();
	 }
}

執行測試用例時候報 Method ‘initializationError’ not found.Opening test class 錯誤。
在這裏插入圖片描述
通過點擊SpringRunner 查看源碼發現有如下注釋:
在這裏插入圖片描述
如果想使用 SpringRunner 進行啓動junit 必須是4.12 或者更高的版本才行。自己spring 項目junit 版本是4.10所以報錯。果斷切換成4.12後就沒有問題了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章