Spring Boot 单元测试

一、概述

SpringBoot1.x 使用 Junit4,SpringBoot2.x 使用 Junit5。

Junit4需要类似如下代码,Junit5单个启动器时不再需要,多个启动器时才需注明class属性。

// Junit4
@RunWith(SpringJunit4ClassRunner.class)
@SpringBootTest(class = SpringbootJunitTestApplication.class)
public XxxTestClass() {
}
// Junit5
@SpringBootTest
public XxxTestClass() {
}

Junit5坐标

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <!--提供junit3和junit4运行平台-->
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

二、测试场景

2.1 RESTFUL 测试

日后完善....

参考资料

1、IBM JUnit 5 简介(第1部分)
2、IBM JUnit 5 简介(第2部分)

评论

暂无评论