@@ -46,7 +46,7 @@ concurrent test execution. It can be enabled and configured using the following
4646
4747`junit.vintage.execution.parallel.enabled=true|false`::
4848 Enable/disable parallel execution (defaults to `false`).
49- Requires opt-in for `classes` or `methods` to be executed in parallel using the configuration parameters below.
49+ Requires opt-in for `classes` or `methods` to be executed in parallel using the configuration parameters below.
5050
5151`junit.vintage.execution.parallel.classes=true|false`::
5252 Enable/disable parallel execution of test classes (defaults to `false`).
@@ -56,8 +56,10 @@ Requires opt-in for `classes` or `methods` to be executed in parallel using the
5656
5757`junit.vintage.execution.parallel.pool-size=<number>`::
5858 Specifies the size of the thread pool to be used for parallel execution.
59- By default, the number of available processors is used.
59+ By default, the number of available processors is used.
6060
61+ [[migrating-from-junit4-parallel-execution-class-level]]
62+ ==== Parallelization at Class Level
6163
6264Let's assume we have two test classes `FooTest` and `BarTest` with each class containing three unit tests.
6365Now, let's enable the parallel execution of test classes:
@@ -66,6 +68,7 @@ Now, let's enable the parallel execution of test classes:
6668----
6769junit.vintage.execution.parallel.enabled=true
6870junit.vintage.execution.parallel.classes=true
71+ junit.vintage.execution.parallel.pool-size=2
6972----
7073
7174With this setup, the `VintageTestEngine` will use two different threads,
@@ -81,13 +84,17 @@ ForkJoinPool-1-worker-1 - BarTest::test3
8184ForkJoinPool-1-worker-2 - FooTest::test3
8285----
8386
84- On the other hand, we can enable the parallel test execution at a `method` level,
87+ [[migrating-from-junit4-parallel-execution-method-level]]
88+ ==== Parallelization at Method Level
89+
90+ Alternatively, we can enable the parallel test execution at a `method` level,
8591rather than the `class` level:
8692
8793[source,properties]
8894----
8995junit.vintage.execution.parallel.enabled=true
9096junit.vintage.execution.parallel.methods=true
97+ junit.vintage.execution.parallel.pool-size=4
9198----
9299
93100Therefore, the test methods from within a class will be executed in parallel,
@@ -104,13 +111,17 @@ ForkJoinPool-1-worker-2 - FooTest::test2
104111ForkJoinPool-1-worker-1 - FooTest::test3
105112----
106113
114+ [[migrating-from-junit4-parallel-execution-class-and-method-level]]
115+ ==== Full Parallelization
116+
107117Finally, we can also enable the parallelization at both `class` and `method` level:
108118
109119[source,properties]
110120----
111121junit.vintage.execution.parallel.enabled=true
112122junit.vintage.execution.parallel.classes=true
113123junit.vintage.execution.parallel.methods=true
124+ junit.vintage.execution.parallel.pool-size=8
114125----
115126
116127With these properties set, the `VintageTestEngine` will execute all the tests classes
@@ -126,6 +137,41 @@ ForkJoinPool-1-worker-5 - BarTest::test2
126137ForkJoinPool-1-worker-4 - BarTest::test1
127138----
128139
140+ [[migrating-from-junit4-parallel-execution-disabled]]
141+ ==== Sequential Execution
142+
143+ On the other hand, if we disable the parallel execution, the `VintageTestEngine`
144+ will execute the tests sequentially, regardless of the other properties:
145+
146+ [source,properties]
147+ ----
148+ junit.vintage.execution.parallel.enabled=false
149+ junit.vintage.execution.parallel.classes=true
150+ junit.vintage.execution.parallel.methods=true
151+ ----
152+
153+ Similarly, the parallelization won't work if we only enable the parallel execution,
154+ but we don't specifically enable a parallel execution level:
155+
156+ [source,properties]
157+ ----
158+ junit.vintage.execution.parallel.enabled=true
159+ junit.vintage.execution.parallel.classes=false
160+ junit.vintage.execution.parallel.methods=false
161+ ----
162+
163+ In such cases, all the tests will be executed sequentially:
164+ [source,plaintext]
165+ ----
166+ main - BarTest::test1
167+ main - BarTest::test2
168+ main - BarTest::test3
169+
170+ main - FooTest::test1
171+ main - FooTest::test2
172+ main - FooTest::test3
173+ ----
174+
129175[[migrating-from-junit4-tips]]
130176=== Migration Tips
131177
0 commit comments