码迷,mamicode.com
首页 > 编程语言 > 详细

springboot整合测试

时间:2019-12-19 19:22:53      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:一个   ann   pack   color   cto   tca   art   factor   return   

第一步:添加测试的依赖

 <!--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(), "第一个父级依赖的工程");
	}

}

 

springboot整合测试

标签:一个   ann   pack   color   cto   tca   art   factor   return   

原文地址:https://www.cnblogs.com/wang66a/p/12069305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!