Skip to content

Commit 87fa2a2

Browse files
Coen90fmbenhassine
authored andcommitted
Deprecate support for JUnit 4
Resolves #4816
1 parent a08c43c commit 87fa2a2

File tree

4 files changed

+11
-43
lines changed

4 files changed

+11
-43
lines changed

spring-batch-docs/modules/ROOT/pages/testing.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ NOTE: If the test context contains a single `Job` bean definition, this
2424
bean will be autowired in `JobOperatorTestUtils`. Otherwise, the job
2525
under test should be manually set on the `JobOperatorTestUtils`.
2626

27+
NOTE: As of Spring Batch 6.0, JUnit 4 is no longer supported. Migration to JUnit Jupiter is recommended.
28+
2729

2830
[tabs]
2931
====

spring-batch-test/src/main/java/org/springframework/batch/test/JobScopeTestExecutionListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* <pre>
3939
* &#064;ContextConfiguration
4040
* &#064;TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class })
41-
* &#064;RunWith(SpringJUnit4ClassRunner.class)
41+
* &#064;SpringJUnitConfig
4242
* public class JobScopeTestExecutionListenerIntegrationTests {
4343
*
4444
* // A job-scoped dependency configured in the ApplicationContext
@@ -64,6 +64,7 @@
6464
* @author Dave Syer
6565
* @author Jimmy Praet
6666
* @author Mahmoud Ben Hassine
67+
* @author Hyuntae Park
6768
*/
6869
public class JobScopeTestExecutionListener implements TestExecutionListener {
6970

spring-batch-test/src/main/java/org/springframework/batch/test/StepScopeTestExecutionListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* <pre>
4040
* &#064;ContextConfiguration
4141
* &#064;TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class })
42-
* &#064;RunWith(SpringJUnit4ClassRunner.class)
42+
* &#064;SpringJUnitConfig
4343
* public class StepScopeTestExecutionListenerIntegrationTests {
4444
*
4545
* // A step-scoped dependency configured in the ApplicationContext
@@ -66,6 +66,7 @@
6666
* @author Chris Schaefer
6767
* @author Mahmoud Ben Hassine
6868
* @author Stefano Cordio
69+
* @author Hyuntae Park
6970
*/
7071
public class StepScopeTestExecutionListener implements TestExecutionListener {
7172

spring-batch-test/src/main/java/org/springframework/batch/test/context/SpringBatchTest.java

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,9 @@
4343
* {@link JobScopeTestExecutionListener} as test execution listeners which are required to
4444
* test step/job scoped beans.</li>
4545
* </ul>
46-
* <p>
47-
* A typical usage of this annotation with JUnit 4 is like the following:
4846
*
49-
* <pre class="code">
50-
* &#064;RunWith(SpringRunner.class)
51-
* &#064;SpringBatchTest
52-
* &#064;ContextConfiguration(classes = MyBatchJobConfiguration.class)
53-
* public class MyBatchJobTests {
54-
*
55-
* &#064;Autowired
56-
* private JobOperatorTestUtils jobOperatorTestUtils;
57-
*
58-
* &#064;Autowired
59-
* private JobRepositoryTestUtils jobRepositoryTestUtils;
60-
*
61-
* &#064;Autowired
62-
* private Job jobUnderTest;
63-
*
64-
* &#064;Before
65-
* public void setup() {
66-
* this.jobRepositoryTestUtils.removeJobExecutions();
67-
* this.jobOperatorTestUtils.setJob(this.jobUnderTest); // this is optional if the job is unique
68-
* }
69-
*
70-
* &#064;Test
71-
* public void testMyJob() throws Exception {
72-
* // given
73-
* JobParameters jobParameters = this.jobOperatorTestUtils.getUniqueJobParameters();
74-
*
75-
* // when
76-
* JobExecution jobExecution = this.jobOperatorTestUtils.startJob(jobParameters);
77-
*
78-
* // then
79-
* Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
80-
* }
81-
*
82-
* }
83-
* </pre>
84-
*
85-
* For JUnit 5, this annotation can be used without manually registering the
86-
* {@link SpringExtension} since {@code @SpringBatchTest} is meta-annotated with
47+
* This annotation can be used without manually registering the {@link SpringExtension}
48+
* since {@code @SpringBatchTest} is meta-annotated with
8749
* {@code @ExtendWith(SpringExtension.class)}. Here is an example:
8850
*
8951
* <pre class="code">
@@ -126,10 +88,12 @@
12688
* <code>JobLauncher</code> beans for this annotation to properly set up test utilities.
12789
* In the previous example, the imported configuration class
12890
* <code>MyBatchJobConfiguration</code> is expected to have such beans defined in it (or
129-
* imported from another configuration class). </strong>
91+
* imported from another configuration class). </strong> <strong> JUnit4 support is
92+
* deprecated in Spring Batch 6.0.0 and will be removed in a future release.</strong>
13093
*
13194
* @author Mahmoud Ben Hassine
13295
* @author Taeik Lim
96+
* @author Hyuntae Park
13397
* @since 4.1
13498
* @see JobOperatorTestUtils
13599
* @see JobRepositoryTestUtils

0 commit comments

Comments
 (0)