Conditional skipping of TestNG tests

后端 未结 5 1181
猫巷女王i
猫巷女王i 2021-02-09 07:21

I don\'t have much experience with TestNG annotations, however I am trying to build a test suite using TestNG framework and POM design pattern for a retail website. I am plannin

5条回答
  •  深忆病人
    2021-02-09 07:59

    You can use TestNG's annotation transformer to set the disabled property of a @Test annotation to true or false.

    Example:

    public class MyTransformer implements IAnnotationTransformer {
        public void transform(ITest annotation, Class testClass,
            Constructor testConstructor, Method testMethod){
    
            if (isTestDisabled(testMethod.getName()))) {
                annotation.setEnabled(false);
            }
        }
    
        public boolean isTestDisabled(String testName){
           // Do whatever you like here to determine if test is disabled or not
        }
    }
    

提交回复
热议问题