测试
Spring Boot提供了许多实用工具和注解来帮助测试您的应用程序。
测试支持由两个模块提供:spring-boot-test
包含核心项目,spring-boot-test-autoconfigure
支持测试的自动配置。
大多数开发人员使用 spring-boot-starter-test
starter,它引入了Spring Boot测试模块以及JUnit Jupiter、AssertJ、Hamcrest和其他一些有用的库。
如果您有使用JUnit 4的测试,可以使用JUnit 5的vintage引擎来运行它们。
要使用vintage引擎,添加对 junit-vintage-engine
的依赖,如下例所示:
<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>
hamcrest-core
被排除,以支持 spring-boot-starter-test
中包含的 org.hamcrest:hamcrest
。