测试

Spring Boot 提供了许多实用工具和注解,以帮助测试您的应用程序。

测试支持由两个通用模块提供:spring-boot-test 包含核心项,spring-boot-test-autoconfigure 支持测试的自动配置,以及几个专注的 -test 模块,为特定功能提供测试支持。

大多数开发者使用 spring-boot-starter-test 启动器,它导入了两个通用 Spring Boot 测试模块以及 JUnit Jupiter、AssertJ、Hamcrest 和其他一些有用的库,以及适用于其特定应用程序的专注 -test 模块。

如果您的测试使用 JUnit 4,可以使用 JUnit 6 的 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 被排除,取而代之的是 org.hamcrest:hamcrest,它是 spring-boot-starter-test 的一部分。

© . This site is unofficial and not affiliated with VMware.