Spring整合junit的配置過程圖解
阿新 • • 發佈:2020-02-27
配置步驟:
1.匯入Spring整合Junit的jar(座標):
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.2.RELEASE</version> <scope>test</scope> </dependency>
2.使用Junit提供的一個註解@Runwith()把原有的main方法替換成spring提供的,這樣就可以建立容器了:
3.告知Spring的執行器,spring的容器建立是基於xml的還是基於註解的,並且說明位置;
@ContextConfiguration
基於xml:location:指定xml檔案的位置,加上classpath關鍵字,表示在類路徑下
基於註解:classes:指定註解類所在的位置
4.注意!當我們使用spring 5.x版本的時候,要求junit的jar必須是4.12及以上!!!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。