Skip to content

Commit 8fb7a6c

Browse files
committed
Remove JUnit 5's vintage engine from spring-boot-starter-test
Closes gh-21625
1 parent 721399b commit 8fb7a6c

File tree

7 files changed

+13
-141
lines changed

7 files changed

+13
-141
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,32 +6251,34 @@ Most developers use the `spring-boot-starter-test` "`Starter`", which imports bo
62516251

62526252
[TIP]
62536253
====
6254-
The starter also brings the vintage engine so that you can run both JUnit 4 and JUnit 5 tests.
6255-
If you have migrated your tests to JUnit 5, you should exclude JUnit 4 support, as shown in the following example:
6254+
If you have tests that use JUnit 4, JUnit 5's vintage engine can be used to run them.
6255+
To use the vintage engine, add a dependency on `junit-vintage-engine`, as shown in the following example:
62566256
62576257
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
62586258
----
62596259
<dependency>
6260-
<groupId>org.springframework.boot</groupId>
6261-
<artifactId>spring-boot-starter-test</artifactId>
6260+
<groupId>org.junit.vintage</groupId>
6261+
<artifactId>junit-vintage-engine</artifactId>
62626262
<scope>test</scope>
62636263
<exclusions>
62646264
<exclusion>
6265-
<groupId>org.junit.vintage</groupId>
6266-
<artifactId>junit-vintage-engine</artifactId>
6265+
<groupId>org.hamcrest</groupId>
6266+
<artifactId>hamcrest-core</artifactId>
62676267
</exclusion>
62686268
</exclusions>
62696269
</dependency>
62706270
----
62716271
====
62726272

6273+
`hamcrest-core` is excluded in favor of `org.hamcrest:hamcrest` that is part of `spring-boot-starter-test`.
6274+
62736275

62746276

62756277
[[boot-features-test-scope-dependencies]]
62766278
=== Test Scope Dependencies
62776279
The `spring-boot-starter-test` "`Starter`" (in the `test` `scope`) contains the following provided libraries:
62786280

6279-
* https://junit.org/junit5/[JUnit 5] (including the vintage engine for backward compatibility with JUnit 4): The de-facto standard for unit testing Java applications.
6281+
* https://junit.org/junit5/[JUnit 5]: The de-facto standard for unit testing Java applications.
62806282
* {spring-framework-docs}/testing.html#integration-testing[Spring Test] & Spring Boot Test: Utilities and integration test support for Spring Boot applications.
62816283
* https://assertj.github.io/doc/[AssertJ]: A fluent assertion library.
62826284
* https://github.com/hamcrest/JavaHamcrest[Hamcrest]: A library of matcher objects (also known as constraints or predicates).
@@ -8100,10 +8102,6 @@ While it is possible to use JUnit 4 to test Kotlin code, JUnit 5 is provided by
81008102
JUnit 5 enables a test class to be instantiated once and reused for all of the class's tests.
81018103
This makes it possible to use `@BeforeClass` and `@AfterClass` annotations on non-static methods, which is a good fit for Kotlin.
81028104

8103-
JUnit 5 is the default and the vintage engine is provided for backward compatibility with JUnit 4.
8104-
If you don't use it, exclude `org.junit.vintage:junit-vintage-engine`.
8105-
You also need to {junit5-docs}/#writing-tests-test-instance-lifecycle-changing-default[switch test instance lifecycle to "per-class"].
8106-
81078105
To mock Kotlin classes, https://mockk.io/[MockK] is recommended.
81088106
If you need the `Mockk` equivalent of the Mockito specific <<boot-features-testing-spring-boot-applications-mocking-beans,`@MockBean` and `@SpyBean` annotations>>, you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations.
81098107

spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id "org.springframework.boot.starter"
33
}
44

5-
description = "Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito"
5+
description = "Starter for testing Spring Boot applications with libraries including JUnit Jupiter, Hamcrest and Mockito"
66

77
dependencies {
88
api(platform(project(":spring-boot-project:spring-boot-dependencies")))
@@ -14,9 +14,6 @@ dependencies {
1414
api("org.assertj:assertj-core")
1515
api("org.hamcrest:hamcrest")
1616
api("org.junit.jupiter:junit-jupiter")
17-
api("org.junit.vintage:junit-vintage-engine") {
18-
exclude group: "org.hamcrest", module: "hamcrest-core"
19-
}
2017
api("org.mockito:mockito-core")
2118
api("org.mockito:mockito-junit-jupiter")
2219
api("org.skyscreamer:jsonassert")

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/build.gradle

Lines changed: 0 additions & 26 deletions
This file was deleted.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ description = "Spring Boot JUnit Vintage smoke test"
77

88
dependencies {
99
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
10-
1110
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
11+
testImplementation("org.junit.vintage:junit-vintage-engine") {
12+
exclude group: "org.hamcrest", module: "hamcrest-core"
13+
}
1214
}
1315

1416
test {

0 commit comments

Comments
 (0)