我有一個實現了IInvokedMethodListener的TestNG偵聽器。在@BeforeMethod我需要設置一些測試情況下,這裏的例子:它是一種在配置階段在TestNG監聽器中獲取測試方法名稱的方法嗎?
public class ThucydidesInvokedMethodListener implements IInvokedMethodListener2 {
public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult) {
boolean areBeforeMethods = method.getTestMethod().getTestClass().getBeforeTestMethods().length > 0;
if ((areBeforeMethods && method.getTestMethod().getTestClass().getBeforeTestMethods()[0] == method.getTestMethod()) ||
!areBeforeMethods && method.isTestMethod()) {
final ThucydidesTestContext context = new ThucydidesTestContext(testResult);
testResult.setAttribute(contextKey(), context);
context.before();
}
}
而且我需要後BeforeMethod在報告中使用這個測試的名字將被執行的測試名稱。這可能使用TestNG? 另外我試過IInvokedMethodListener2,它還有ITestContext,但它不提供測試名稱。