spring boot使用junit Test

概述

本文主要介绍如何在spring boot项目中使用junit测试模块功能

方法一/使用spring-boot自带的junit测试功能

引入maven依赖

        <!-- Test  start-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!-- Test end -->

测试类,需要和启动类保持同级

    @RunWith(SpringRunner.class)
    @SpringBootTest
    @EnableTransactionManagement
    public class ApplicationTests {

    @Resource
    private TrtcMixStreamService trtcMixStreamService;

    @Test
    public void test() throws InterruptedException {
        TrtcStartMixStreamModel trtcStartMixStreamModel = new TrtcStartMixStreamModel();
        trtcStartMixStreamModel.setRoomId(84L);
        trtcStartMixStreamModel.setUserId("180");
        trtcStartMixStreamModel.setMixStreamId("szpc_84_playUrl");
        trtcStartMixStreamModel.initBaseModelInfo("1255516392", "cee491af9d286ff3d3ca3ec6a1d2d621", "1400321747");
        trtcMixStreamService.openCloudMixStream(trtcStartMixStreamModel);
        System.out.println("等待10秒");
        Thread.sleep(10000);
        trtcMixStreamService.cancelCloudMixStream(trtcStartMixStreamModel);
    }

    //  @Test
    public void test2() throws InterruptedException {
        TrtcStartMixStreamModel trtcStartMixStreamModel = new TrtcStartMixStreamModel();
        trtcStartMixStreamModel.setRoomId(86L);
        trtcStartMixStreamModel.setUserId("180");
        trtcStartMixStreamModel.setMixStreamId("szpc_86_playUrl");
        trtcStartMixStreamModel.initBaseModelInfo("1255516392", "cee491af9d286ff3d3ca3ec6a1d2d621", "1400321747");
        trtcMixStreamService.cancelCloudMixStream(trtcStartMixStreamModel);
    }

}

总结

spring boot junit 已经集成了junit和mokito,使用起来比较方便,完善的代码需要jnit测试保证


   Reprint policy


《spring boot使用junit Test》 by jackromer is licensed under a Creative Commons Attribution 4.0 International License
 Previous
mybatis-plus实现自定义分页 mybatis-plus实现自定义分页
概述 本文主要介绍如何使用mybatis-plus实现复杂自定义分页 使用说明 接口定义 /** * 分页查询 * // 此处最好返回IPAGE */ APIResult<IPage<ResDTO>>
2020-05-06 jackromer
Next 
触发器实现业务日志等功能 触发器实现业务日志等功能
mysql 触发器 概述 本文主要介绍如何使用触发器实现业务功能。 一个简单的触发器 此触发器实现单条记录在插入前的数据更改和链接操作 BEGIN DECLARE newRoomId BIG
2020-03-17 jackromer
  目录