添加依赖
dependencies {
compile('org.springframework.boot:spring-boot-starter-webflux')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("org.junit.jupiter:junit-jupiter-api")
testRuntime("org.junit.jupiter:junit-jupiter-engine")
}
创建测试类
@DataJpaTest
// 添加下面这个注解就可以运行测试了
@ExtendWith(SpringExtension.class)
class Junit5Test {
@Autowired
TestEntityManager entityManager;
@Test
void runTest() {
entityManager.persist(new User(100));
}
}
本文介绍如何在 Spring Boot 项目中使用 JUnit5 进行单元测试。通过添加必要的依赖并创建测试类,演示了如何利用 TestEntityManager 对象进行数据持久化操作。
5419

被折叠的 条评论
为什么被折叠?



