...
Code Block |
---|
@ParameterizedTest @ValueSource(strings = {"Hello", "JUnit"}) void withValueSource (String word){ assertNotNull(word); } |
Can contain one @BeforeEach method, and one @AfterEach method, but because Java doesn’t allow static members in inner classes, the @BeforeAll and @AfterAll methods don’t work by default.
Code Block |
---|
class JUnit5NestedExampleTest {
...
@Nested
@DisplayName("Tests in the nested class A") class A {
...
@Test
@DisplayName("Example test for method A")
void sampleTestForMethodA() {
//test logic
}
@Nested
@DisplayName("Another nested test class") class B {
//test logic
}
}
} |
Extensions model allows third parties to extend JUnit with their own additions. It is useful when a developer wants to use some features that absent in default JUnit version.
Now five main types of extension points can be used: test instance post-processing, conditional test execution, life-cycle callback, parameter resolution, exception handling.
An extension will be executed only if a class marked the corresponding annotation. For detailed information, please take a look at the tutorial.
Migration from JUnit 4 to 5 is not so difficult, as backward compatibility is available.
...