测试

Spring Boot 提供了许多实用程序和注释,可以在测试应用程序时提供帮助。 测试支持由两个模块提供:spring-boot-test包含核心项目,并且spring-boot-test-autoconfigure支持测试的自动配置。spring-doc.cadn.net.cn

大多数开发人员使用spring-boot-starter-teststarter,它导入了 Spring Boot 测试模块以及 JUnit Jupiter、AssertJ、Hamcrest 和许多其他有用的库。spring-doc.cadn.net.cn

如果您有使用 JUnit 4 的测试,则可以使用 JUnit 5 的老式引擎来运行它们。 要使用复古引擎,请添加依赖项junit-vintage-engine,如以下示例所示: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>

hamcrest-core被排除在外,有利于org.hamcrest:hamcrest这是spring-boot-starter-test.spring-doc.cadn.net.cn