這篇文章主要介紹了springboottest測試依賴和使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
springboottest測試依賴和使用
1 2 3 4 | <dependency>??? <groupId>org.springframework.boot</groupId>??? <artifactId>spring-boot-starter-test</artifactId></dependency> |
創建測試類
注意加運行啟動注解,和springbootest注解文章源自四五設計網-http://www.133122.cn/39443.html
1 2 3 4 5 6 7 8 9 10 11 12 13 | @RunWith(SpringRunner.class)@SpringBootTestpublic class User01MapperTest {???? @Autowired??? User01Mapper user01Mapper;???? @Test??? public void testQuery(){??? ? ? User01 user = user01Mapper.selectByPrimaryKey("張三");??? ? ? System.out.println(user);??? }} |
maven無法使用spring test注解
看pom.xml中是否已經引入了spring test的依賴
如果沒有,加入以下依賴文章源自四五設計網-http://www.133122.cn/39443.html
1 2 3 4 5 | <dependency>????<groupId>org.springframework</groupId>????<artifactId>spring-test</artifactId>????<version>4.1.3.RELEASE</version></dependency> |
注意:加入新的依賴后,要maven->update project,導入一下spring-test的jar包文章源自四五設計網-http://www.133122.cn/39443.html
如果已經有依賴了,還是不能使用Spring-test的注解,那么看看libraries中的spring-test.jar包,如果是黑色的,如下圖。文章源自四五設計網-http://www.133122.cn/39443.html
文章源自四五設計網-http://www.133122.cn/39443.html
把依賴中的test去掉,test表示只能在src下的test文件夾使用。文章源自四五設計網-http://www.133122.cn/39443.html
1 2 3 4 5 6 | <dependency>????<groupId>org.springframework</groupId>????<artifactId>spring-test</artifactId>????<version>4.1.3.RELEASE</version>????<!-- <scope>test</scope> --></dependency> |
以上為個人經驗,希望能給大家一個參考。文章源自四五設計網-http://www.133122.cn/39443.html 文章源自四五設計網-http://www.133122.cn/39443.html
繼續閱讀
我的微信
微信掃一掃

我的微信
惠生活福利社
微信掃一掃

我的公眾號

評論