diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 90d8c26c1b4..51d900f4c6f 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -6251,32 +6251,34 @@ Most developers use the `spring-boot-starter-test` "`Starter`", which imports bo [TIP] ==== -The starter also brings the vintage engine so that you can run both JUnit 4 and JUnit 5 tests. -If you have migrated your tests to JUnit 5, you should exclude JUnit 4 support, as shown in the following example: +If you have tests that use JUnit 4, JUnit 5's vintage engine can be used to run them. +To use the vintage engine, add a dependency on `junit-vintage-engine`, as shown in the following example: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- - org.springframework.boot - spring-boot-starter-test + org.junit.vintage + junit-vintage-engine test - org.junit.vintage - junit-vintage-engine + org.hamcrest + hamcrest-core ---- ==== +`hamcrest-core` is excluded in favor of `org.hamcrest:hamcrest` that is part of `spring-boot-starter-test`. + [[boot-features-test-scope-dependencies]] === Test Scope Dependencies The `spring-boot-starter-test` "`Starter`" (in the `test` `scope`) contains the following provided libraries: -* 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. +* https://junit.org/junit5/[JUnit 5]: The de-facto standard for unit testing Java applications. * {spring-framework-docs}/testing.html#integration-testing[Spring Test] & Spring Boot Test: Utilities and integration test support for Spring Boot applications. * https://assertj.github.io/doc/[AssertJ]: A fluent assertion library. * 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 JUnit 5 enables a test class to be instantiated once and reused for all of the class's tests. This makes it possible to use `@BeforeClass` and `@AfterClass` annotations on non-static methods, which is a good fit for Kotlin. -JUnit 5 is the default and the vintage engine is provided for backward compatibility with JUnit 4. -If you don't use it, exclude `org.junit.vintage:junit-vintage-engine`. -You also need to {junit5-docs}/#writing-tests-test-instance-lifecycle-changing-default[switch test instance lifecycle to "per-class"]. - To mock Kotlin classes, https://mockk.io/[MockK] is recommended. If you need the `Mockk` equivalent of the Mockito specific <>, you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations. diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle index d852b9138c5..e44be1dabab 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-test/build.gradle @@ -2,7 +2,7 @@ plugins { id "org.springframework.boot.starter" } -description = "Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito" +description = "Starter for testing Spring Boot applications with libraries including JUnit Jupiter, Hamcrest and Mockito" dependencies { api(platform(project(":spring-boot-project:spring-boot-dependencies"))) @@ -14,9 +14,6 @@ dependencies { api("org.assertj:assertj-core") api("org.hamcrest:hamcrest") api("org.junit.jupiter:junit-jupiter") - api("org.junit.vintage:junit-vintage-engine") { - exclude group: "org.hamcrest", module: "hamcrest-core" - } api("org.mockito:mockito-core") api("org.mockito:mockito-junit-jupiter") api("org.skyscreamer:jsonassert") diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/build.gradle deleted file mode 100644 index f9e563f2509..00000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - id "java" - id "org.springframework.boot.conventions" -} - -description = "Spring Boot JUnit Jupiter smoke test" - -dependencies { - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) - - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) { - exclude group: "org.junit.vintage" - } -} - -test { - testLogging { - afterSuite { description, result -> - if (!description.parent) { - if (!result.testCount) { - throw new GradleException("No tests were executed") - } - } - } - } -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java deleted file mode 100644 index 89f71100568..00000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class MessageController { - - @GetMapping("/hi") - public String hello() { - return "Hello World"; - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java deleted file mode 100644 index 33a7851b62c..00000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJUnitJupiterApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJUnitJupiterApplication.class, args); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java deleted file mode 100644 index 1c62ce2dff1..00000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJUnitJupiterApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testMessage() { - String message = this.restTemplate.getForObject("/hi", String.class); - assertThat(message).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle index 8212bce053a..d44518a14d4 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/build.gradle @@ -7,8 +7,10 @@ description = "Spring Boot JUnit Vintage smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) + testImplementation("org.junit.vintage:junit-vintage-engine") { + exclude group: "org.hamcrest", module: "hamcrest-core" + } } test {