此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1Spring中文文档

Spring Boot 提供了许多实用程序和注释,以帮助测试您的应用程序。 测试支持由两个模块提供:包含核心项,支持测试自动配置。spring-boot-testspring-boot-test-autoconfigureSpring中文文档

大多数开发人员使用“Starter”,它既导入了 Spring Boot 测试模块,也导入了 JUnit Jupiter、AssertJ、Hamcrest 和许多其他有用的库。spring-boot-starter-testSpring中文文档

如果您有使用 JUnit 4 的测试,则可以使用 JUnit 5 的老式引擎来运行它们。 若要使用 vintage 引擎,请添加对 的依赖项,如以下示例所示:junit-vintage-engineSpring中文文档

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

如果您有使用 JUnit 4 的测试,则可以使用 JUnit 5 的老式引擎来运行它们。 若要使用 vintage 引擎,请添加对 的依赖项,如以下示例所示:junit-vintage-engineSpring中文文档

<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被排除在外,赞成 是 的一部分。org.hamcrest:hamcrestspring-boot-starter-testSpring中文文档