Description
@TestFactory
can return a stream of DynamicContainers
and DynamicTest
. It would be awesome if we could run containers in parallel, but the tests within containers on the same thread.
The @Execution
seems to only allow you to switch from everything parallel/concurrent or everything on the same thread.
The configuration parameters junit.jupiter.execution.parallel.mode.default
and junit.jupiter.execution.parallel.mode.classes.default
also don't seem to allow such a configuration, probably because all test suites and test are coming from the same class
.
For example: the following should allow tests test1
and test2
that are in suite1
to be run on the same thread, and the tests in suite2
to be run on a different, but consistent thread:
static class Runner {
@TestFactory
Stream<DynamicNode> systemTest() {
final Stream<DynamicNode> tests1 = Stream.of(
DynamicTest.dynamicTest("test1", () -> {System.out.println(Thread.currentThread().getId() + " -test1");}),
DynamicTest.dynamicTest("test2", () -> {System.out.println(Thread.currentThread().getId() + " - test2");}));
final Stream<DynamicNode> tests2 = Stream.of(
DynamicTest.dynamicTest("test3", () -> {System.out.println(Thread.currentThread().getId() + " -test3");}),
DynamicTest.dynamicTest("test4", () -> {System.out.println(Thread.currentThread().getId() + " - test4");}));
return Stream.of(
DynamicContainer.dynamicContainer("suite1", tests1),
DynamicContainer.dynamicContainer("suite2", tests2));
}
}
Maybe this could be achieved via one or more of:
- a new
junit.jupiter.execution.parallel.mode.container.default
property - a field on
@TestFactory
to control execution - an enhancement to
@Execution
- a parameter to
DynamicContainer
Thanks!