Spring Boot整合Junit,@RunWith和@SpringBootTest的使用
1、在pom.xml添加junit啟動器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
2、編寫測試類
/**
* main方法:
* ApplicationContext ac=new
* ClassPathXmlApplicationContext("classpath:applicationContext.xml");
* junit與spring整合:
* @RunWith(SpringJUnit4ClassRunner.class):讓junit與spring環(huán)境進行整合
* @Contextconfiguartion("classpath:applicationContext.xml")
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes={App.class})//App是項目的啟動類名稱
public class UserServiceTest {
@Autowired
private UserServiceImpl userServiceImpl;
@Test
public void testAddUser(){
this.userServiceImpl.addUser();
}
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-800519.html
文章來源:http://www.zghlxwxcb.cn/news/detail-800519.html
到了這里,關(guān)于Spring Boot整合Junit,@RunWith和@SpringBootTest的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!