zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    小程序生命周期
    async/await实现图片的串行、并行加载
    移动应用区别
    小程序组件
    secureCRT
    LInux
    java实现八大排序算法
    求出所有排列 去重全排列 回溯算法
    二分法基本思想
    异常
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13237002.html
Copyright © 2011-2022 走看看