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

  • 相关阅读:
    返回一个整数数组中子数组的最大值
    软工概论第二周个人项目四则运算二(改进)
    构建之法阅读笔记01
    单例模式
    .net基础加强
    使用jquery easy ui
    抽象工厂类
    System.Linq.Expressions.Expression
    创建上下文对象
    DBSesson
  • 原文地址:https://www.cnblogs.com/zhushilai/p/13534927.html
Copyright © 2011-2022 走看看