测试

Spring Boot 提供了多种工具和注释,帮助测试你的应用程序。spring-doc.cadn.net.cn

测试支持由两个通用模块提供——Spring靴测试包含核心物品和Spring-boot-test-autoconfigure支持测试的自动配置——并且有多个重点配置-测试提供特定功能的测试支持的模块。spring-doc.cadn.net.cn

大多数开发者使用Spring靴启动测试starter 可以导入通用的 Spring Boot 测试模块,以及 JUnit Jupiter、AssertJ、Hamcrest 以及其他一些有用的库,并且-测试适用于其特定应用的模块。spring-doc.cadn.net.cn

如果你有使用 JUnit 4 的测试,可以使用 JUnit 6 的老引擎来运行。 要使用老旧引擎,可以添加依赖Junit-复古发动机如下例所示:spring-doc.cadn.net.cn

<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>

哈姆克雷斯特-核心被排除,取而代之的是org.hamcrest:hamcrestSpring靴启动测试.spring-doc.cadn.net.cn