Top Description Methods
org.junit.jupiter.api

public Interface TestInfo

Annotations
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.STABLE

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.

Since
5.0
See Also
Test, RepeatedTest, TestFactory, BeforeEach, AfterEach, BeforeAll, AfterAll, DisplayName, Tag

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the display name of the test or container; never null or blank
getDisplayName
()

Get the display name of the current test or container.

public Set<String>
getTags()

Get the set of all tags for the current test or container.

public Optional<Class<?>>
getTestClass()

Get the Class associated with the current test or container, if available.

public Optional<Method>
getTestMethod()

Get the Method associated with the current test or container, if available.

Method Detail

getDisplayNameback 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 @DisplayName.

Default Display Names

If the context in which TestInfo is used is at the container level, the default display name is generated based on the name of the test class. For top-level and @Nested test classes, the default display name is the simple name of the class. For static nested test classes, the default display name is the default display name for the enclosing class concatenated with the simple name of the static nested class, separated by a dollar sign ($). For example, the default display names for the following test classes are TopLevelTests, NestedTests, and TopLevelTests$StaticTests.

  class TopLevelTests {

     @Nested
     class NestedTests {}

     static class StaticTests {}
  }

If the context in which TestInfo is used is at the test level, the default display name is the name of the test method concatenated with a comma-separated list of simple names of the parameter types in parentheses. For example, the default display name for the following test method is testUser(TestInfo, User).

  @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.

Returns:String

the display name of the test or container; never null or blank

getTagsback to summary
public Set<String> getTags()

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.

getTestClassback to summary
public Optional<Class<?>> getTestClass()

Get the Class associated with the current test or container, if available.

getTestMethodback to summary
public Optional<Method> getTestMethod()

Get the Method associated with the current test or container, if available.