How do I get the name of the test method that was run in a testng tear down method?

前端 未结 5 1674
遇见更好的自我
遇见更好的自我 2020-12-01 08:00

Basically, I have a teardown method that I want to log to the console which test was just run. How would I go about getting that string?

I can get the class name, bu

5条回答
  •  天涯浪人
    2020-12-01 08:21

    Declare a parameter of type ITestResult in your @AfterMethod and TestNG will inject it:

    @AfterMethod
    public void afterMethod(ITestResult result) {
      System.out.println("method name:" + result.getMethod().getMethodName());
    }
    

提交回复
热议问题