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 测试
日后完善....

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论