SpringBoot Test集成测试
1.pom,文件添加相关依赖
如何测试SpringBoot的请求?使用spring-boot-starter-test
这个包即可完成测试,SpringBoot项目为什么需要测试本章不作过多说明,重点放在测试代码上。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version> 1.5.1.RELEASE</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version> 1.5.1.RELEASE</version>
使用说明
@RunWith(SpringRunner.class) @SpringBootTest(classes = MposApplication.class) public class TestClass { @Autowired private TerminalTypeMapper terminalTypeMapper;//注入dao接口 @Test public void testFind() { System.out.println("测试开始"); //简单验证结果集是否正确 TerminalTypeDO type = terminalTypeMapper.getTemrminalNameById(1L); System.out.println(type); }
相关博客地址:https://www.cnblogs.com/liweipower2015/p/6765137.html
http://www.jianshu.com/p/5defb8d8e83a
http://blog.csdn.net/dounine/article/details/72953463