zoukankan      html  css  js  c++  java
  • 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(), "第一个父级依赖的工程");
    	}
    
    }
    小蘑菇
  • 相关阅读:
    HTML <input> 标签
    HTML5 <input> type 属性
    静态页面与动态页面
    string::size_type 页73 size_t 页90
    template method(模板方法)
    C++中创建对象的时候加括号和不加括号的区别(转)
    _declspec(dllexport)和.def(转)
    智能指针
    C++中的delete加深认识
    工厂方法(整理自李建忠<C++设计模式>视频)
  • 原文地址:https://www.cnblogs.com/wang66a/p/12069305.html
Copyright © 2011-2022 走看看