• junit5了解一下


    1. 要求java8及以上版本
    2. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

    https://junit.org/junit5/docs/current/user-guide/#overview-java-versions

    https://junit.org/junit5/

    中文版:https://sjyuan.cc/junit5/user-guide-cn/

    spring boot的测试用例:

    package com.dudu;
    
    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
    public class Chapter1ApplicationTests {
    
        @Test
        public void contextLoads() {
        }
    
    }

    对应的pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.dudu</groupId>
        <artifactId>chapter1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>chapter1</name>
        <description>Demo project for Spring Boot</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.2.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>5.1.4.RELEASE</version>
                <scope>test</scope>
            </dependency>

          <!--使用spring-boot的单元测试时,需要显式引入下面的maven依赖-->

            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.0.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
                <version>4.12.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

    参考

    https://blog.csdn.net/swordcenter/article/details/79279094

  • 相关阅读:
    hugo博客使用 utterances 作为评论系统
    使用DEM生成彩色的立体图像
    hibernate Annotation 注解形式 实例 事务 hibernate.cfg.xml
    web.xml配置webAppRootKey 的问题
    JAVA 生成二维码 代码
    关于Boost库的split函数在不同的编译器下的使用
    纯 hibernate hibernate.cfg.xml 事务 数据库操作 CRUD
    Android 百度地图API 定位 导航 代码
    Android GPS
    使用GDAL对DEM进行彩色渲染
  • 原文地址:https://www.cnblogs.com/shengulong/p/10369093.html
Copyright © 2020-2023  润新知