public class OrderMethods implements IMethodInterceptor, IInvokedMethodListener {
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
Comparator<IMethodInstance> comparator = Comparator.comparing(
o -> o.getMethod().getMethodName());
methods.sort(comparator.reversed());
return methods;
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
System.err.println(method.getTestMethod().getQualifiedName() + "()");
}
}
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/fb3dc695-4c2f-4f3d-85b5-e16bc5c4d160n%40googlegroups.com.
The IMethodInterceptor works fine, however it intervenes before the dataproviders are set.
What I would like to acheive is :testAAA(DP1), testBBB(DP1), testAAA(DP2), testBBB(DP2)
private static Comparator<IMethodInstance> comparator() {
return (o1, o2) -> {
String m1 = computeMethodName(o1);
String m2 = computeMethodName(o2);
return m1.compareTo(m2);
};
}
private static String computeMethodName(IMethodInstance im) {
Object instance = extractEmbeddedObject(im.getMethod());
boolean considerParameters = instance instanceof IParameterInfo;
if (considerParameters) {
IParameterInfo ip = (IParameterInfo) instance;
return im.getMethod().getMethodName() + "<" +
Arrays.toString(ip.getParameters()) + ">";
}
return im.getMethod().getMethodName();
}
private static Object extractEmbeddedObject(ITestNGMethod tm) {
try {
List<Field> fields = new ArrayList<>();
Class<?> clazz = tm.getClass();
while (!clazz.equals(Object.class)) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
return fields.stream()
.filter(f -> f.getName().equals("m_instance"))
.findFirst()
.map(in -> {
in.setAccessible(true);
try {
return in.get(tm);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}).orElse(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/53e2b651-27ef-42ff-b6a5-fa78a3d040c3n%40googlegroups.com.