更新时间:2023-11-20 08:28:16
在测试方法中声明类型为TestInfo
的参数,JUnit会自动为该方法提供该实例的一个实例:
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());
}
您可以从TestInfo
实例中获得测试方法名称(以及更多),如上所示.
You can get test method name (and more) from the TestInfo
instance as shown above.