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()

  • 相关阅读:
    泛海精灵软件预发布统计报告 & 反馈
    【scrum】2.23
    VS2010中C#添加图片(资源)
    用XML存储程序的配置
    scrum 2.28
    【Scrum】2.24
    《人月神话》读书心得
    微软R&D喜欢什么人才
    “电脑族”应多做下肢运动
    ASCII表
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13237002.html
Copyright © 2011-2022 走看看