• SpringBoot单元测试


    引入相关依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>

    配置相关注解

    package net.cyb.demo;
    
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = {DemoProject1Application.class})
    public class VideoTest {
        @Before
        public void testOne(){
            System.out.println("这个是测试Before");
        }
        @Test
        public void testTwo(){
            System.out.println("这个是测试Test");
        }
        @After
        public void testThree(){
            System.out.println("这个是测试After");
        }
    }

    常用单元测试的注解

    • @Before
    • @Test
    • @After

    断言

    判断程序结果是否符合预期TestCase.assertxxxx()

  • 相关阅读:
    java中的四种内部类
    09_TomCat_基础知识
    08_XML的解析_SAX解析
    IO流07_输入输出流总体系
    IO流06_处理流
    IO流05_OutputStream和Writer输出流
    IO流04_InputStream和Reader输入流
    IO流03_流的分类和概述
    IO流02_文件过滤器
    IO流01_File类
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13237002.html
Copyright © 2020-2023  润新知