springboot整合测试
第一步:添加测试的依赖
<!--springboot整合测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>第二步:创建测试类
package www.it.test.com;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import junit.framework.TestCase;
import www.it.com.controller.RedisController;
/**
* @author 作者 :wangjie
* @version 创建时间:2019年8月25日 下午3:45:54
* 类说明 @SpringBootTest指定测试的类
@RunWith(SpringJUnit4ClassRunner.class)指定用哪一个类进行测试
*/
@SpringBootTest(classes=RedisController.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class SpringbootTest {
@Autowired
private RedisController redisController;
public RedisController getRedisController() {
return redisController;
}
public void setRedisController(RedisController redisController) {
this.redisController = redisController;
}
/**
* 编写测试类
*/
@Test
public void test() {
//firstParent方法的返回值是否和期待的值一样
TestCase.assertEquals(this.redisController.firstParent(), "第一个父级依赖的工程");
}
} 相关推荐
shirleypaddy 2020-10-19
qingmumu 2020-10-19
敏敏张 2020-11-11
SCNUHB 2020-11-10
小木兮子 2020-11-11
WasteLand 2020-10-18
Cocolada 2020-11-12
杜鲁门 2020-11-05
Testingba工作室 2020-09-15
周公周金桥 2020-09-13
专注前端开发 2020-08-16
emagtestage 2020-08-16
heniancheng 2020-08-15
hanjinixng00 2020-08-12
小方哥哥 2020-08-09
83327712 2020-07-30
卖小孩的咖啡 2020-07-21