基本上,我有一个拆卸方法,我想登录到刚刚运行测试的控制台。我将如何获取该字符串?
我可以得到类名,但我想要刚刚执行的实际方法。
public class TestSomething {
@AfterMethod
public void tearDown() {
System.out.println("The test that just ran was: " + getTestThatJustRanMethodName());
}
@Test
public void testCase() {
assertTrue(1 == 1);
}
}
...应该输出到屏幕:“刚刚运行的测试是:testCase”
但是,我不知道 getTestThatJustRanMethodName
实际上应该是什么魔法。
最佳答案
在@AfterMethod 中声明一个 ITestResult 类型的参数,TestNG 将注入(inject)它:
@AfterMethod
public void afterMethod(ITestResult result) {
System.out.println("method name:" + result.getMethod().getMethodName());
}
关于java - 如何获取在 testng 拆卸方法中运行的测试方法的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2952202/