@@ -60,7 +60,87 @@ concurrent test execution. It can be enabled and configured using the following
6060  Specifies the size of the thread pool to be used for parallel execution. By default, the
6161  number of available processors is used.
6262
63- Example configuration in `junit-platform.properties`:
63+ [[migrating-from-junit4-parallel-execution-class-level]]
64+ ==== Parallelization at Class Level
65+ 
66+ Let's assume we have two test classes `FooTest` and `BarTest` with each class containing
67+ three unit tests. Now, let's enable parallel execution of test classes:
68+ 
69+ [source,properties]
70+ ---- 
71+ junit.vintage.execution.parallel.enabled=true 
72+ junit.vintage.execution.parallel.classes=true 
73+ ---- 
74+ 
75+ With this setup, the `VintageTestEngine` will use two different threads,
76+ one for each test class:
77+ 
78+ [source,plaintext]
79+ ---- 
80+ ForkJoinPool-1-worker-1 - BarTest::test1 
81+ ForkJoinPool-1-worker-2 - FooTest::test1 
82+ ForkJoinPool-1-worker-1 - BarTest::test2 
83+ ForkJoinPool-1-worker-2 - FooTest::test2 
84+ ForkJoinPool-1-worker-1 - BarTest::test3 
85+ ForkJoinPool-1-worker-2 - FooTest::test3 
86+ ---- 
87+ 
88+ [[migrating-from-junit4-parallel-execution-method-level]]
89+ ==== Parallelization at Method Level
90+ 
91+ Alternatively, we can enable parallel test execution at a method level,
92+ rather than the class level:
93+ 
94+ [source,properties]
95+ ---- 
96+ junit.vintage.execution.parallel.enabled=true 
97+ junit.vintage.execution.parallel.methods=true 
98+ ---- 
99+ 
100+ Therefore, the test methods within each class will be executed in parallel, while
101+ different test classes will be executed sequentially:
102+ 
103+ [source,plaintext]
104+ ---- 
105+ ForkJoinPool-1-worker-1 - BarTest::test1 
106+ ForkJoinPool-1-worker-2 - BarTest::test2 
107+ ForkJoinPool-1-worker-3 - BarTest::test3 
108+ 
109+ ForkJoinPool-1-worker-3 - FooTest::test1 
110+ ForkJoinPool-1-worker-2 - FooTest::test2 
111+ ForkJoinPool-1-worker-1 - FooTest::test3 
112+ ---- 
113+ 
114+ [[migrating-from-junit4-parallel-execution-class-and-method-level]]
115+ ==== Full Parallelization
116+ 
117+ Finally, we can also enable parallelization at both class and method level:
118+ 
119+ [source,properties]
120+ ---- 
121+ junit.vintage.execution.parallel.enabled=true 
122+ junit.vintage.execution.parallel.classes=true 
123+ junit.vintage.execution.parallel.methods=true 
124+ ---- 
125+ 
126+ With these properties set, the `VintageTestEngine` will execute all tests classes and
127+ methods in parallel, potentially significantly reducing the overall test suite execution time:
128+ 
129+ [source,plaintext]
130+ ---- 
131+ ForkJoinPool-1-worker-6 - FooTest::test2 
132+ ForkJoinPool-1-worker-7 - BarTest::test3 
133+ ForkJoinPool-1-worker-3 - FooTest::test1 
134+ ForkJoinPool-1-worker-8 - FooTest::test3 
135+ ForkJoinPool-1-worker-5 - BarTest::test2 
136+ ForkJoinPool-1-worker-4 - BarTest::test1 
137+ ---- 
138+ 
139+ [[migrating-from-junit4-parallel-execution-pool-size]]
140+ ==== Configuring the Pool Size
141+ 
142+ The default thread pool size is equal to the number of available processors. However, we
143+ can also configure the pool size explicitly:
64144
65145[source,properties]
66146---- 
@@ -70,8 +150,39 @@ junit.vintage.execution.parallel.methods=true
70150junit.vintage.execution.parallel.pool-size=4 
71151---- 
72152
73- With these properties set, the `VintageTestEngine` will execute tests in parallel,
74- potentially significantly reducing the overall test suite execution time.
153+ For instance, if we update our previous example that uses full parallelization and
154+ configure the pool size to four, we can expect to see our six test methods executed with
155+ a parallelism of four:
156+ 
157+ [source,plaintext]
158+ ---- 
159+ ForkJoinPool-1-worker-2 - FooTest::test1 
160+ ForkJoinPool-1-worker-4 - BarTest::test2 
161+ ForkJoinPool-1-worker-3 - BarTest::test1 
162+ ForkJoinPool-1-worker-4 - BarTest::test3 
163+ ForkJoinPool-1-worker-2 - FooTest::test2 
164+ ForkJoinPool-1-worker-3 - FooTest::test3 
165+ ---- 
166+ 
167+ As we can see, even though we set the thread pool size was four, only three threads were
168+ used in this case. This happens because the pool adjusts the number of active threads
169+ based on workload and system needs.
170+ 
171+ [[migrating-from-junit4-parallel-execution-disabled]]
172+ ==== Sequential Execution
173+ 
174+ On the other hand, if we disable parallel execution, the `VintageTestEngine`
175+ will execute all tests sequentially, regardless of the other properties:
176+ 
177+ [source,properties]
178+ ---- 
179+ junit.vintage.execution.parallel.enabled=false 
180+ junit.vintage.execution.parallel.classes=true 
181+ junit.vintage.execution.parallel.methods=true 
182+ ---- 
183+ 
184+ Similarly, tests will be executed sequentially if you enable parallel execution in general
185+ but enable neither class-level nor method-level parallelization.
75186
76187[[migrating-from-junit4-tips]]
77188=== Migration Tips
0 commit comments