テスト

Spring Boot は、アプリケーションをテストするときに役立つ多くのユーティリティとアノテーションを提供します。テストサポートは 2 つのモジュールによって提供されます。spring-boot-test にはコアアイテムが含まれ、spring-boot-test-autoconfigure はテストの自動構成をサポートします。

ほとんどの開発者は、Spring Boot テストモジュールと JUnit Jupiter、AssertJ、Hamcrest、その他の便利なライブラリの両方をインポートする spring-boot-starter-test “Starter”を使用します。

JUnit 4 を使用するテストがある場合、JUnit 5 の 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 が優先されます。