r/java • • Aug 05 '26

Hacking the Method Name

https://maxxedev.github.io/2026/08/05/hacking-the-method-name.html
33 Upvotes

7 comments sorted by

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