• springboot单元测试之Junit(一)


    1springboot单元测试的依赖jar 

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

     2新建一个测试类SpringBootTestDemo 

    package com.example.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;

    import junit.framework.TestCase;

    /**
    *
    * @author Administrator
    * @RunWith(SpringRunner.class) 底层启动Junit 类似于SpringMVC中的SpringJUit4ClassRunner
    * @SpringBootTest(classes= {DemoApplication.class}) 启动整个DempApplication工具
    */
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes= {DemoApplication.class})
    public class SpringBootTestDemo {
    /**
    * TestCase.assertEquals Junit4断言比较
    */
    @Test
    public void testOne1() {
    System.out.println("test one1");
    TestCase.assertEquals(1, 1);
    }

    @Test
    public void testOne2() {
    System.out.println("test one2");
    TestCase.assertEquals(2, 2);
    }


    @Before
    public void testBefore() {
    System.out.println("before");
    }

    @After
    public void afterBefore() {
    System.out.println("after");
    }


    }

    3然后run as  SpringBootTestDemo

  • 相关阅读:
    撩课-Python-每天5道面试题-第8天
    声明提前、原型、静态方法的一些所得
    梳理ajax
    两数之和、整数反转、回文数
    node 基础API(fs)
    node 基础API(event)
    node 基础API(Buffer)
    node 基础API(path)
    node 调试技巧
    node process(进程) 几个常用属性
  • 原文地址:https://www.cnblogs.com/zhushilai/p/13534927.html
Copyright © 2020-2023  润新知