I have written an AnnotationTransformer to disable certain tests.
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;
public class AnnotationTransformer implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
if (checkOsAndtestCaseName(testMethod)) {
annotation.setEnabled(false);
}
}
private boolean checkOsAndtestCaseName(Method testMethod) {
if (testMethod.getName().toLowerCase().contains("win")
&& System.getProperty("
os.name").toLowerCase().equals("linux")) {
return true;
} else if (testMethod.getName().toLowerCase().contains("unix")
&& System.getProperty("
os.name").toLowerCase().equals("windows")) {
return true;
}
return false;
}
}
In my testcase I try to use it with.