zoukankan      html  css  js  c++  java
  • springboot 测试代码

    主要用于自己查阅
    该方法同样适用于,测试数据库
    不适用于测试,前端,websocket等

    MAVEN 依赖

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

    如果有问题,可以继续导入

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    

    使用方式

    import org.junit.jupiter.api.Test;
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    //添加如下注解
    @RunWith(SpringRunner.class)
    @SpringBootTest
    class ZzdDemoApplicationTests {
    
        @Test
        void contextLoads() {
           //在此写入测试代码
        }
    }
    

    当处于一个分布式的项目中

    springBootTest得指定想要测试的项目的启动类

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = AppApplication.class)//对应的项目启动类
    public class TestDemo {
    
        @Test
        public void ss(){
            System.out.println("aa");
        }
    }
    
  • 相关阅读:
    http返回码
    WCF 超时
    MVC异步
    熔断设计模式
    JAVA学习图
    java io模型
    keep alive 长连接
    Java异常处理 误区
    架构的本质
    Repository模式
  • 原文地址:https://www.cnblogs.com/Kevin-QAQ/p/13818895.html
Copyright © 2011-2022 走看看