這篇文章主要介紹了springboottest測試依賴和使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
springboottest測試依賴和使用
1 2 3 4 | <dependency>??? <groupId>org.springframework.boot</groupId>??? <artifactId>spring-boot-starter-test</artifactId></dependency> |
創(chuàng)建測試類
注意加運(yùn)行啟動(dòng)注解,和springbootest注解文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/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中是否已經(jīng)引入了spring test的依賴
如果沒有,加入以下依賴文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/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,導(dǎo)入一下spring-test的jar包文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/39443.html
如果已經(jīng)有依賴了,還是不能使用Spring-test的注解,那么看看libraries中的spring-test.jar包,如果是黑色的,如下圖。文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/39443.html
文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/39443.html
把依賴中的test去掉,test表示只能在src下的test文件夾使用。文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/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> |
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考。文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/39443.html 文章源自四五設(shè)計(jì)網(wǎng)-http://m.wasochina.com/39443.html



評(píng)論