What is the equivalent of TestName rule in JUnit 5?

十年热恋 提交于 2019-12-05 00:20:37

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.

Personally I prefer to use this:

System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!