Remove mentions of JUnit 4

This commit removes all mentions of JUnit 4 from the Javadoc and
reference documentation. It also harmonizes to simply refers to JUnit.

Closes gh-47228
This commit is contained in:
Stéphane Nicoll 2025-09-19 15:29:11 +02:00
parent 8d000e008f
commit 3b98af30f5
26 changed files with 11 additions and 63 deletions

View File

@ -44,7 +44,7 @@ The `nativeCompile` task of the GraalVM Native Image plugin is automatically con
[[aot.processing-tests]]
== Processing Tests
The AOT engine can be applied to JUnit 5 tests that use Spring's Test Context Framework.
The AOT engine can be applied to JUnit tests that use Spring's Test Context Framework.
Suitable tests are processed by the `processTestAot` task to generate `ApplicationContextInitializer` code.
As with application AOT processing, the `BeanFactory` is fully prepared at build-time.
As with `processAot`, the `processTestAot` task is `JavaExec` subclass and can be configured as needed to influence this processing.

View File

@ -89,7 +89,7 @@ include::partial$goals/process-aot.adoc[leveloffset=+1]
[[aot.processing-tests]]
== Processing Tests
The AOT engine can be applied to JUnit 5 tests that use Spring's Test Context Framework.
The AOT engine can be applied to JUnit tests that use Spring's Test Context Framework.
Those tests are processed by the AOT engine and are then executed in a native image.
Just like <<aot.processing-applications.using-the-native-profile,for production code>>, the `spring-boot-starter-parent` defines a `nativeTest` profile that can be used to streamline the steps required to execute your tests in a native image.

View File

@ -40,6 +40,7 @@ class TestTypeExcludeFilterTests {
private final MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
@Test
@Deprecated(since = "4.0.0")
void matchesJUnit4TestClass() throws Exception {
assertThat(this.filter.match(getMetadataReader(TestTypeExcludeFilterTests.class), this.metadataReaderFactory))
.isTrue();

View File

@ -49,7 +49,7 @@ import org.springframework.util.ClassUtils;
* {@link ApplicationContext} and/or custom {@link ImportSelector} implementations.
* <p>
* This class is primarily intended for use with tests that need to specify configuration
* classes but can't use {@link org.springframework.test.context.junit4.SpringRunner}.
* classes.
* <p>
* Implementations of this class should be annotated with {@link Order @Order} or
* implement {@link Ordered}.

View File

@ -142,8 +142,7 @@ Note that some features (such as detecting the default value or deprecated items
[[features.kotlin.testing]]
== Testing
While it is possible to use JUnit 4 to test Kotlin code, JUnit 5 is provided by default and is recommended.
JUnit 5 enables a test class to be instantiated once and reused for all of the class's tests.
JUnit enables a test class to be instantiated once and reused for all of the class's tests.
This makes it possible to use javadoc:org.junit.jupiter.api.BeforeAll[format=annotation] and javadoc:org.junit.jupiter.api.AfterAll[format=annotation] annotations on non-static methods, which is a good fit for Kotlin.
To mock Kotlin classes, https://mockk.io/[MockK] is recommended.

View File

@ -8,7 +8,7 @@ Most developers use the `spring-boot-starter-test` starter, which imports both S
[TIP]
====
If you have tests that use JUnit 4, JUnit 5's vintage engine can be used to run them.
If you have tests that still use JUnit 4, JUnit'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]

View File

@ -9,8 +9,7 @@ Spring Boot provides a javadoc:org.springframework.boot.test.context.SpringBootT
The annotation works by xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.detecting-configuration[creating the javadoc:org.springframework.context.ApplicationContext[] used in your tests through javadoc:org.springframework.boot.SpringApplication[]].
In addition to javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] a number of other annotations are also provided for xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[testing more specific slices] of an application.
TIP: If you are using JUnit 4, do not forget to also add `@RunWith(SpringRunner.class)` to your test, otherwise the annotations will be ignored.
If you are using JUnit 5, there is no need to add the equivalent `@ExtendWith(SpringExtension.class)` as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] and the other `@...Test` annotations are already annotated with it.
If you are using JUnit, there is no need to add the equivalent `@ExtendWith(SpringExtension.class)` as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] and the other `@...Test` annotations are already annotated with it.
By default, javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] will not start a server.
You can use the `webEnvironment` attribute of javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] to further refine how your tests run:

View File

@ -3,7 +3,7 @@
The `spring-boot-starter-test` starter (in the `test` `scope`) contains the following provided libraries:
* https://junit.org/junit5/[JUnit 5]: The de-facto standard for unit testing Java applications.
* https://junit.org/junit5/[JUnit]: The de-facto standard for unit testing Java applications.
* {url-spring-framework-docs}/testing/integration.html[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).

View File

@ -28,9 +28,9 @@ import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.test.util.ReflectionTestUtils;
/**
* JUnit 5 {@link Extension} for tests that interact with Spring Boot's {@link Handler}
* for {@code jar:} URLs. Ensures that the handler is registered prior to test execution
* and cleans up the handler's root file cache afterwards.
* JUnit {@link Extension} for tests that interact with Spring Boot's {@link Handler} for
* {@code jar:} URLs. Ensures that the handler is registered prior to test execution and
* cleans up the handler's root file cache afterwards.
*
* @author Andy Wilkinson
*/

View File

@ -43,9 +43,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data Casandra
* tests. Similarly, component scanning is limited to Cassandra repositories and entities
* ({@code @Table}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Artsiom Yudovin
* @author Stephane Nicoll

View File

@ -43,9 +43,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data
* Couchbase tests. Similarly, component scanning is limited to Couchbase repositories and
* entities ({@code @Document}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Eddú Meléndez
* @since 2.7.0

View File

@ -43,9 +43,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data
* Elasticsearch tests. Similarly, component scanning is limited to Elasticsearch
* repositories and entities ({@code @Document}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Eddú Meléndez
* @since 2.7.0

View File

@ -57,9 +57,6 @@ import org.springframework.transaction.annotation.Transactional;
* database, you should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} rather than this
* annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Andy Wilkinson
* @since 2.1.0

View File

@ -46,9 +46,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* <p>
* By default, tests annotated with {@code @DataLdapTest} will use an embedded in-memory
* LDAP process (if available).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Eddú Meléndez
* @author Artsiom Yudovin

View File

@ -43,9 +43,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data Mongo
* tests. Similarly, component scanning is limited to Mongo repositories and entities
* ({@code @Document}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Michael Simons
* @author Stephane Nicoll

View File

@ -49,9 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
* usual test-related semantics (i.e. rollback by default). This feature is not supported
* with reactive access so this should be disabled by annotating the test class with
* {@code @Transactional(propagation = Propagation.NOT_SUPPORTED)}.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Eddú Meléndez
* @author Stephane Nicoll

View File

@ -42,9 +42,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data R2DBC
* tests. Similarly, component scanning is limited to R2DBC repositories and entities
* ({@code @Table}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Mark Paluch
* @author Stephane Nicoll

View File

@ -43,9 +43,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* Using this annotation only enables auto-configuration that is relevant to Data Redis
* tests. Similarly, component scanning is limited to Redis repositories and entities
* ({@code @RedisHash}).
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Jayaram Pradhan
* @author Artsiom Yudovin

View File

@ -55,9 +55,6 @@ import org.springframework.transaction.annotation.Transactional;
* database, you should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} rather than this
* annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin

View File

@ -49,9 +49,6 @@ import org.springframework.transaction.annotation.Transactional;
* want to replace any explicit or usually auto-configured DataSource by an embedded
* in-memory database, the {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase}
* annotation can be used to override these settings.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Michael Simons
* @author Stephane Nicoll

View File

@ -57,9 +57,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* {@link JacksonTester}, {@link JsonbTester} and {@link GsonTester} fields. More
* fine-grained control can be provided through the
* {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters} annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Phillip Webb
* @author Artsiom Yudovin

View File

@ -62,9 +62,6 @@ import org.springframework.transaction.annotation.Transactional;
* database, you should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} rather than this
* annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Phillip Webb
* @author Artsiom Yudovin

View File

@ -63,9 +63,6 @@ import org.springframework.web.client.RestTemplate;
* If you are testing a bean that doesn't use {@link RestTemplateBuilder} but instead
* injects a {@link RestTemplate} directly, you can add
* {@code @AutoConfigureWebClient(registerRestTemplate=true)}.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Stephane Nicoll
* @author Phillip Webb

View File

@ -76,9 +76,6 @@ import org.springframework.test.web.reactive.server.WebTestClient;
* you should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureWebTestClient @AutoConfigureWebTestClient} rather than this
* annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin

View File

@ -83,9 +83,6 @@ import org.springframework.test.web.servlet.MockMvc;
* If you are looking to load your full application configuration and use MockMVC, you
* should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureMockMvc @AutoConfigureMockMvc} rather than this annotation.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Phillip Webb
* @author Artsiom Yudovin

View File

@ -48,9 +48,6 @@ import org.springframework.ws.test.client.MockWebServiceServer;
* If you are testing a bean that doesn't use {@link WebServiceTemplateBuilder} but
* instead injects a {@link WebServiceTemplate} directly, you can add
* {@code @AutoConfigureWebServiceClient(registerWebServiceTemplate=true)}.
* <p>
* When using JUnit 4, this annotation should be used in combination with
* {@code @RunWith(SpringRunner.class)}.
*
* @author Dmytro Nosan
* @since 2.3.0