zoukankan      html  css  js  c++  java
  • SpringBoot测试方法

    1.添加依赖

    <dependency>
      <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-test</artifactId>   <scope>test</scope> </dependency>

    2.目录结构

    3.编写代码

    TestApp.java
    import org.junit.After;
    import org.junit.Before;
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    import org.springframework.test.context.web.WebAppConfiguration;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = TestApp.class)
    @WebAppConfiguration
    public class TestApp {
    
        @Before
        public void init() {
            System.out.println("Begin-----------------");
        }
        @After
        public void after() {
            System.out.println("End-----------------");
    
        }
    }
    RealTest.java
    import org.junit.Test;
    import java.util.stream.IntStream;
    
    public class RealTest extends TestApp{
        @Autowired
        private TestService testservice;
        @Test
        public void test(){
            IntStream.range(0,10).forEach(i -> System.out.println(i));
    
        }
        @Test
        public void test1(){
            IntStream.rangeClosed(0,10).forEach( i -> System.out.println(i));
        }
    }
    

      

    4.想跑那个测试方法点哪个就行了

      

  • 相关阅读:
    Effective_STL 学习笔记(四十) 使仿函数类可适配
    Effective_STL 学习笔记(三十九) 用纯函数做判断式
    PMP考试大纲
    小技巧
    git 常用命令
    java web的返回值对象
    工作任务-SM敏捷核心思维
    树莓派上手
    spring 公用异常处理
    前端现在版本怎么这么乱
  • 原文地址:https://www.cnblogs.com/sjxbg/p/14204875.html
Copyright © 2011-2022 走看看