テスト

Spring Boot は、アプリケーションのテストに役立つさまざまなユーティリティとアノテーションを提供します。

テストサポートは、2 つの汎用モジュール (コア項目を含む spring-boot-test と、テストの自動構成をサポートする spring-boot-test-autoconfigure ) と、特定の機能のテストサポートを提供するいくつかの重点的な -test モジュールによって提供されます。

ほとんどの開発者は、汎用 Spring Boot テストモジュールと JUnit Jupiter、AssertJ、Hamcrest、その他の便利なライブラリ、特定のアプリケーションに適用可能な重点的な -test モジュールの両方をインポートする spring-boot-starter-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 は除外され、spring-boot-starter-test の一部である org.hamcrest:hamcrest が優先されます。