Amazing Features In JUnit 5

Sam Jing Wen
3 min readMar 5, 2023

Display Name Generators

JUnit 5 has support for customizing test class and test method names. We can use JUnit 5 custom display name generators via the @DisplayNameGeneration annotation.

To get started, JUnit 5 provides a ReplaceUnderscores class that replaces any underscores in names with spaces. However, the @DisplayName annotation takes precedence over any display name generator.

@DisplayNameGeneration(ReplaceUnderscores.class)
class This_is_a_test_class {
@Test
void divisible_by_zero() {
assertEquals(42 % 2, 0);
}

@Test
@DisplayName("this is a negative check test")
void is_negative() {
assertTrue(-1 < 0);
}
}

When we run the test, we see that the output is more readable.

2. Parallel Execution

Parallel test execution is an experimental feature available as an opt-in since version 5.3.
To enable parallel execution, set the following configuration parameters in junit-platform.properties

junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent

Synchronization:

--

--