TestInfo is used to inject information about the current test or
container into to @Test, @RepeatedTest,
@ParameterizedTest, @TestFactory, @BeforeEach,
@AfterEach, @BeforeAll, and @AfterAll methods.
If a method parameter is of type TestInfo, JUnit will supply
an instance of TestInfo corresponding to the current test or
container as the value for the parameter.
Test, RepeatedTest, TestFactory, BeforeEach, AfterEach, BeforeAll, AfterAll, DisplayName, Tag
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the display name of the test or container; nevernull or blankGet the display name of the current test or container. |
| public Set | |
| public Optional | |
| public Optional |
| getDisplayName | back to summary |
|---|---|
| public String getDisplayName() Get the display name of the current test or container. The display name is either a default name or a custom name configured
via Default Display NamesIf the context in which
class TopLevelTests {
@Nested
class NestedTests {}
static class StaticTests {}
}
If the context in which
@Test
void testUser(TestInfo testInfo, @Mock User user) {}
Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
| |
| getTags | back to summary |
|---|---|
| public Set Get the set of all tags for the current test or container. Tags may be declared directly on the test element or inherited from an outer context. | |
| getTestClass | back to summary |
|---|---|
| public Optional Get the | |
| getTestMethod | back to summary |
|---|---|
| public Optional Get the | |