1 package test.methodinterceptors; 2 3 import org.testng.IMethodInstance; 4 import org.testng.IMethodInterceptor; 5 import org.testng.ITestContext; 6 import org.testng.annotations.Test; 7 8 import java.util.ArrayList; 9 import java.util.HashSet; 10 import java.util.List; 11 import java.util.Set; 12 13 public class FastTestsFirstInterceptor implements IMethodInterceptor { 14 @Override intercept(List<IMethodInstance> methods, ITestContext context)15 public List<IMethodInstance> intercept(List<IMethodInstance> methods, 16 ITestContext context) 17 { 18 List<IMethodInstance> result = new ArrayList<>(); 19 for (IMethodInstance m : methods) { 20 Test test = m.getMethod().getMethod().getAnnotation(Test.class); 21 Set<String> groups = new HashSet<>(); 22 for (String group : test.groups()) { 23 groups.add(group); 24 } 25 if (groups.contains("fast")) { 26 result.add(0, m); 27 } 28 else { 29 result.add(m); 30 } 31 } 32 return result; 33 } 34 35 } 36