侦听器IInvokedMethodListener允许您在 TestNG 即将调用测试(使用@Test注释)或配置(使用任何@Before或@After注释)方法时收到通知。您需要实现以下接口:

    1. public interface IInvokedMethodListener extends ITestNGListener {
    2. void beforeInvocation(IInvokedMethod method, ITestResult testResult);
    3. void afterInvocation(IInvokedMethod method, ITestResult testResult);
    4. }

    并将其声明为侦听器,如有关 TestNG 侦听器的部分所述