That can also be done via stack walking. And test frameworks usually give much more convenient access to this information: Junit4 has the TestName rule, Junit Jupiter will supply it if you declare a TestInfo parameter. In TestNG you can declare a Method parameter in the @BeforeMethod or ITestResults in the @AfterMethod.
View all comments
Show parent comment
8
u/koflerdavid Aug 06 '26 edited Aug 06 '26
That can also be done via stack walking. And test frameworks usually give much more convenient access to this information: Junit4 has the
TestNamerule, Junit Jupiter will supply it if you declare aTestInfoparameter. In TestNG you can declare aMethodparameter in the@BeforeMethodorITestResultsin the@AfterMethod.