Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of TestName rule in JUnit 5?

How can I get name of the test method in JUnit 5?

like image 296
Mahozad Avatar asked Aug 29 '18 10:08

Mahozad


1 Answers

Declare a parameter of type TestInfo in your test method and JUnit will automatically supply an instance of that for the method:

@Test void getTestInfo(TestInfo testInfo) { // Automatically injected     System.out.println(testInfo.getDisplayName());     System.out.println(testInfo.getTestMethod());     System.out.println(testInfo.getTestClass());     System.out.println(testInfo.getTags()); } 

You can get test method name (and more) from the TestInfo instance as shown above.

like image 75
Mahozad Avatar answered Oct 09 '22 21:10

Mahozad