Skip to content

Commit c74fc7e

Browse files
committed
Deprecate JUnit 4 support in the TestContext framework
Closes spring-projectsgh-34794
1 parent 2db1a63 commit c74fc7e

File tree

61 files changed

+215
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+215
-65
lines changed

framework-docs/modules/ROOT/pages/testing/annotations/integration-junit4.adoc

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
[[integration-testing-annotations-junit4]]
22
= Spring JUnit 4 Testing Annotations
33

4+
[WARNING]
5+
====
6+
JUnit 4 support is deprecated since Spring Framework 7.0 in favor of the
7+
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit-jupiter-extension[`SpringExtension`]
8+
and JUnit Jupiter.
9+
====
10+
411
The following annotations are supported only when used in conjunction with the
512
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit4-runner[SpringRunner],
613
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit4-rules[Spring's JUnit 4 rules], or
@@ -206,6 +213,3 @@ Kotlin::
206213
----
207214
<1> Repeat this test ten times.
208215
======
209-
210-
211-

framework-docs/modules/ROOT/pages/testing/testcontext-framework/support-classes.adoc

+21
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ Kotlin::
483483
[[testcontext-junit4-runner]]
484484
=== Spring JUnit 4 Runner
485485

486+
[WARNING]
487+
====
488+
JUnit 4 support is deprecated since Spring Framework 7.0 in favor of the
489+
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit-jupiter-extension[`SpringExtension`]
490+
and JUnit Jupiter.
491+
====
492+
486493
The Spring TestContext Framework offers full integration with JUnit 4 through a custom
487494
runner (supported on JUnit 4.12 or higher). By annotating test classes with
488495
`@RunWith(SpringJUnit4ClassRunner.class)` or the shorter `@RunWith(SpringRunner.class)`
@@ -538,6 +545,13 @@ be configured through `@ContextConfiguration`.
538545
[[testcontext-junit4-rules]]
539546
=== Spring JUnit 4 Rules
540547

548+
[WARNING]
549+
====
550+
JUnit 4 support is deprecated since Spring Framework 7.0 in favor of the
551+
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit-jupiter-extension[`SpringExtension`]
552+
and JUnit Jupiter.
553+
====
554+
541555
The `org.springframework.test.context.junit4.rules` package provides the following JUnit
542556
4 rules (supported on JUnit 4.12 or higher):
543557

@@ -607,6 +621,13 @@ Kotlin::
607621
[[testcontext-support-classes-junit4]]
608622
=== JUnit 4 Base Classes
609623

624+
[WARNING]
625+
====
626+
JUnit 4 support is deprecated since Spring Framework 7.0 in favor of the
627+
xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit-jupiter-extension[`SpringExtension`]
628+
for JUnit Jupiter.
629+
====
630+
610631
The `org.springframework.test.context.junit4` package provides the following support
611632
classes for JUnit 4-based test cases (supported on JUnit 4.12 or higher):
612633

spring-test/src/main/java/org/springframework/test/annotation/IfProfileValue.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,11 +94,15 @@
9494
* @see org.springframework.test.context.junit4.statements.ProfileValueChecker
9595
* @see org.springframework.context.annotation.Profile
9696
* @see org.springframework.test.context.ActiveProfiles
97+
* @deprecated since Spring Framework 7.0 in favor of the
98+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
99+
* and JUnit Jupiter
97100
*/
98101
@Target({ElementType.TYPE, ElementType.METHOD})
99102
@Retention(RetentionPolicy.RUNTIME)
100103
@Documented
101104
@Inherited
105+
@Deprecated(since = "7.0")
102106
public @interface IfProfileValue {
103107

104108
/**

spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSource.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,11 @@
4040
* @see ProfileValueSourceConfiguration
4141
* @see IfProfileValue
4242
* @see ProfileValueUtils
43+
* @deprecated since Spring Framework 7.0 in favor of the
44+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
45+
* and JUnit Jupiter
4346
*/
47+
@Deprecated(since = "7.0")
4448
public interface ProfileValueSource {
4549

4650
/**

spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSourceConfiguration.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,11 +37,15 @@
3737
* @see ProfileValueSource
3838
* @see IfProfileValue
3939
* @see ProfileValueUtils
40+
* @deprecated since Spring Framework 7.0 in favor of the
41+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
42+
* and JUnit Jupiter
4043
*/
4144
@Target(ElementType.TYPE)
4245
@Retention(RetentionPolicy.RUNTIME)
4346
@Documented
4447
@Inherited
48+
@Deprecated(since = "7.0")
4549
public @interface ProfileValueSourceConfiguration {
4650

4751
/**

spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,9 @@
3838
* @see ProfileValueSource
3939
* @see ProfileValueSourceConfiguration
4040
* @see IfProfileValue
41+
* @deprecated since Spring Framework 7.0 with no replacement
4142
*/
43+
@Deprecated(since = "7.0")
4244
public abstract class ProfileValueUtils {
4345

4446
private static final Log logger = LogFactory.getLog(ProfileValueUtils.class);

spring-test/src/main/java/org/springframework/test/annotation/Repeat.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,10 +44,14 @@
4444
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
4545
* @see org.springframework.test.context.junit4.rules.SpringMethodRule
4646
* @see org.springframework.test.context.junit4.statements.SpringRepeat
47+
* @deprecated since Spring Framework 7.0 in favor of the
48+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
49+
* and JUnit Jupiter
4750
*/
4851
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
4952
@Retention(RetentionPolicy.RUNTIME)
5053
@Documented
54+
@Deprecated(since = "7.0")
5155
public @interface Repeat {
5256

5357
/**

spring-test/src/main/java/org/springframework/test/annotation/SystemProfileValueSource.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,11 @@
2525
* @author Rod Johnson
2626
* @author Sam Brannen
2727
* @since 2.0
28+
* @deprecated since Spring Framework 7.0 in favor of the
29+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
30+
* and JUnit Jupiter
2831
*/
32+
@Deprecated(since = "7.0")
2933
public final class SystemProfileValueSource implements ProfileValueSource {
3034

3135
private static final SystemProfileValueSource INSTANCE = new SystemProfileValueSource();

spring-test/src/main/java/org/springframework/test/annotation/TestAnnotationUtils.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,10 @@
2525
*
2626
* @author Sam Brannen
2727
* @since 4.2
28+
* @see org.springframework.test.context.TestContextAnnotationUtils
29+
* @deprecated since Spring Framework 7.0 with no replacement
2830
*/
31+
@Deprecated(since = "7.0")
2932
public abstract class TestAnnotationUtils {
3033

3134
/**

spring-test/src/main/java/org/springframework/test/annotation/Timed.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,10 +43,14 @@
4343
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
4444
* @see org.springframework.test.context.junit4.rules.SpringMethodRule
4545
* @see org.springframework.test.context.junit4.statements.SpringFailOnTimeout
46+
* @deprecated since Spring Framework 7.0 in favor of the
47+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
48+
* and JUnit Jupiter
4649
*/
4750
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
4851
@Retention(RetentionPolicy.RUNTIME)
4952
@Documented
53+
@Deprecated(since = "7.0")
5054
public @interface Timed {
5155

5256
/**

spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,8 +62,12 @@
6262
* @see TestExecutionListeners
6363
* @see AbstractTransactionalJUnit4SpringContextTests
6464
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
65+
* @deprecated since Spring Framework 7.0 in favor of the
66+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
67+
* and JUnit Jupiter
6568
*/
6669
@RunWith(SpringRunner.class)
70+
@Deprecated(since = "7.0")
6771
public abstract class AbstractJUnit4SpringContextTests implements ApplicationContextAware {
6872

6973
/**

spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,8 +78,12 @@
7878
* @see org.springframework.test.context.transaction.AfterTransaction
7979
* @see org.springframework.test.jdbc.JdbcTestUtils
8080
* @see org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests
81+
* @deprecated since Spring Framework 7.0 in favor of the
82+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
83+
* and JUnit Jupiter
8184
*/
8285
@Transactional
86+
@Deprecated(since = "7.0")
8387
public abstract class AbstractTransactionalJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests {
8488

8589
/**

spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,11 @@
9393
* @see AbstractTransactionalJUnit4SpringContextTests
9494
* @see org.springframework.test.context.junit4.rules.SpringClassRule
9595
* @see org.springframework.test.context.junit4.rules.SpringMethodRule
96+
* @deprecated since Spring Framework 7.0 in favor of the
97+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
98+
* and JUnit Jupiter
9699
*/
100+
@Deprecated(since = "7.0")
97101
public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
98102

99103
private static final Log logger = LogFactory.getLog(SpringJUnit4ClassRunner.class);

spring-test/src/main/java/org/springframework/test/context/junit4/SpringRunner.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,11 @@
3535
* @see SpringJUnit4ClassRunner
3636
* @see org.springframework.test.context.junit4.rules.SpringClassRule
3737
* @see org.springframework.test.context.junit4.rules.SpringMethodRule
38+
* @deprecated since Spring Framework 7.0 in favor of the
39+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
40+
* and JUnit Jupiter
3841
*/
42+
@Deprecated(since = "7.0")
3943
public final class SpringRunner extends SpringJUnit4ClassRunner {
4044

4145
/**

spring-test/src/main/java/org/springframework/test/context/junit4/rules/SpringClassRule.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -81,7 +81,11 @@
8181
* @see SpringMethodRule
8282
* @see org.springframework.test.context.TestContextManager
8383
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
84+
* @deprecated since Spring Framework 7.0 in favor of the
85+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
86+
* and JUnit Jupiter
8487
*/
88+
@Deprecated(since = "7.0")
8589
public class SpringClassRule implements TestRule {
8690

8791
private static final Log logger = LogFactory.getLog(SpringClassRule.class);

spring-test/src/main/java/org/springframework/test/context/junit4/rules/SpringMethodRule.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,7 +95,11 @@
9595
* @see SpringClassRule
9696
* @see org.springframework.test.context.TestContextManager
9797
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
98+
* @deprecated since Spring Framework 7.0 in favor of the
99+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
100+
* and JUnit Jupiter
98101
*/
102+
@Deprecated(since = "7.0")
99103
public class SpringMethodRule implements MethodRule {
100104

101105
private static final Log logger = LogFactory.getLog(SpringMethodRule.class);

spring-test/src/main/java/org/springframework/test/context/junit4/statements/ProfileValueChecker.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,11 @@
3939
* @see #evaluate()
4040
* @see IfProfileValue
4141
* @see ProfileValueUtils
42+
* @deprecated since Spring Framework 7.0 in favor of the
43+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
44+
* and JUnit Jupiter
4245
*/
46+
@Deprecated(since = "7.0")
4347
public class ProfileValueChecker extends Statement {
4448

4549
private final Statement next;

spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestClassCallbacks.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,11 @@
3636
* @since 3.0
3737
* @see #evaluate()
3838
* @see RunBeforeTestClassCallbacks
39+
* @deprecated since Spring Framework 7.0 in favor of the
40+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
41+
* and JUnit Jupiter
3942
*/
43+
@Deprecated(since = "7.0")
4044
public class RunAfterTestClassCallbacks extends Statement {
4145

4246
private final Statement next;

spring-test/src/main/java/org/springframework/test/context/junit4/statements/RunAfterTestExecutionCallbacks.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,11 @@
3737
* @since 5.0
3838
* @see #evaluate()
3939
* @see RunBeforeTestExecutionCallbacks
40+
* @deprecated since Spring Framework 7.0 in favor of the
41+
* {@link org.springframework.test.context.junit.jupiter.SpringExtension SpringExtension}
42+
* and JUnit Jupiter
4043
*/
44+
@Deprecated(since = "7.0")
4145
public class RunAfterTestExecutionCallbacks extends Statement {
4246

4347
private final Statement next;

0 commit comments

Comments
 (0)