private static void ignoreTest(ITestAnnotation annotation, Ignore ignore) { if (ignore == null) { return; } annotation.setEnabled(false); updateDescription(annotation, ignore); }
@Override public void transform( ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { annotation.setEnabled(true); } }
private static void ignoreTest(ITestAnnotation annotation, Ignore ignore) { if (ignore == null) { return; } annotation.setEnabled(false); updateDescription(annotation, ignore); }
import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.testng.IAnnotationTransformer; import org.testng.annotations.ITestAnnotation; public class Transformer implements IAnnotationTransformer { // Do not worry about calling this method as testNG calls it behind the scenes before EVERY method (or test). // It will disable single tests, not the entire suite like SkipException public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod){ // If we have chose not to run this test then disable it. if (disableMe()){ annotation.setEnabled(false); } } // logic YOU control private boolean disableMe()){ }
@SuppressWarnings("rawtypes") @Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { String methodName = testMethod.getName(); if (transforms.containsKey(methodName)) { annotation.setEnabled(transforms.get(methodName)); String[] dependencies = annotation.getDependsOnMethods(); for (String dep : dependencies) { transforms.put(dep, true); } } else { // If it is not in the transforms map and defEnabled is true, // do what its annotation says annotation.setEnabled(annotation.getEnabled() && defEnabled); } } }
Constructor arg2, Method testMethod) { if (methodToRun.equals(testMethod.getName())) { annotation.setEnabled(true);