1 package test.annotationtransformer; 2 3 import org.testng.IAnnotationTransformer; 4 import org.testng.annotations.ITestAnnotation; 5 6 import java.lang.reflect.Constructor; 7 import java.lang.reflect.Method; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 public class MyTransformer implements IAnnotationTransformer { 12 13 private final List<String> methodNames = new ArrayList<>(); 14 15 @Override 16 public void transform(ITestAnnotation annotation, Class testClass, 17 Constructor testConstructor, Method testMethod) { 18 annotation.setTimeOut(10000); 19 if (testMethod != null) { 20 switch (testMethod.getName()) { 21 case "three": 22 annotation.setInvocationCount(3); 23 break; 24 case "four": 25 annotation.setInvocationCount(4); 26 break; 27 case "five": 28 annotation.setInvocationCount(5); 29 break; 30 } 31 methodNames.add(testMethod.getName()); 32 } 33 } 34 35 public List<String> getMethodNames() { 36 return methodNames; 37 } 38 } 39