测试
原文:https://docs.spring.io/spring-boot/reference/testing/index.html (Spring Boot 4.2.0)
Spring Boot 提供许多实用工具和注解来帮助测试应用。测试支持由两个通用模块提供——spring-boot-test 包含核心项,spring-boot-test-autoconfigure 支持测试自动配置——以及若干专注于特定特性的 -test 模块。
大多数开发者使用 spring-boot-starter-test starter,它导入两个通用 Spring Boot 测试模块以及 JUnit Jupiter、AssertJ、Hamcrest 和许多其他有用的库,以及适用于其特定应用的专注 -test 模块。
如果有使用 JUnit 4 的测试,可以使用 JUnit 6 的 vintage engine 运行它们。要使用 vintage engine,请添加
junit-vintage-engine依赖,并排除hamcrest-core(因为spring-boot-starter-test已包含org.hamcrest:hamcrest):
<dependency> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> </exclusion> </exclusions> </dependency>