測試

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.