lin
2025-08-01 633231e833e21d5b8b1c00cb15aedb62b3b78e8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package test;
 
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
// TODO replace other test IInvokedMethodListener by this one
public class InvokedMethodNameListener implements IInvokedMethodListener {
 
  private final List<String> invokedMethodNames = new ArrayList<>();
  private final List<String> failedMethodNames = new ArrayList<>();
  private final List<String> skippedMethodNames = new ArrayList<>();
  private final List<String> succeedMethodNames = new ArrayList<>();
 
  @Override
  public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    invokedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
  }
 
  @Override
  public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
    switch (testResult.getStatus()) {
      case ITestResult.FAILURE:
        failedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
        break;
      case ITestResult.SKIP:
        skippedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
        break;
      case ITestResult.SUCCESS:
        succeedMethodNames.add(method.getTestMethod().getConstructorOrMethod().getName());
        break;
    }
  }
 
  public List<String> getInvokedMethodNames() {
    return Collections.unmodifiableList(invokedMethodNames);
  }
 
  public List<String> getFailedMethodNames() {
    return failedMethodNames;
  }
 
  public List<String> getSkippedMethodNames() {
    return skippedMethodNames;
  }
 
  public List<String> getSucceedMethodNames() {
    return succeedMethodNames;
  }
}