• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test.invokedmethodlistener;
2 
3 import org.testng.IInvokedMethod;
4 import org.testng.IInvokedMethodListener;
5 import org.testng.ITestResult;
6 
7 import java.util.HashSet;
8 import java.util.Set;
9 
10 public class InvokedMethodNameListener implements IInvokedMethodListener {
11 
12   final Set<String> testMethods = new HashSet<>();
13   final Set<String> configurationMethods = new HashSet<>();
14   final Set<String> testMethodsFromTM = new HashSet<>();
15   final Set<String> configurationMethodsFromTM = new HashSet<>();
16 
17   @Override
beforeInvocation(IInvokedMethod method, ITestResult testResult)18   public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
19   }
20 
21   @Override
afterInvocation(IInvokedMethod method, ITestResult testResult)22   public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
23     String methodName = method.getTestMethod().getMethodName();
24 
25     if (method.isTestMethod()) {
26       testMethods.add(methodName);
27     }
28     if (method.isConfigurationMethod()) {
29       configurationMethods.add(methodName);
30     }
31     if (method.getTestMethod().isTest()) {
32       testMethodsFromTM.add(methodName);
33     }
34     if (method.getTestMethod().isBeforeMethodConfiguration() ||
35         method.getTestMethod().isAfterMethodConfiguration() ||
36         method.getTestMethod().isBeforeTestConfiguration() ||
37         method.getTestMethod().isAfterTestConfiguration() ||
38         method.getTestMethod().isBeforeClassConfiguration() ||
39         method.getTestMethod().isAfterClassConfiguration() ||
40         method.getTestMethod().isBeforeSuiteConfiguration() ||
41         method.getTestMethod().isAfterSuiteConfiguration()) {
42       configurationMethodsFromTM.add(methodName);
43     }
44   }
45 }
46