How to exclude class in TestNG?

后端 未结 8 1203
囚心锁ツ
囚心锁ツ 2020-12-30 05:17

Is this possible to exclude classes in testng.xml?

I tried with


    

         


        
8条回答
  •  难免孤独
    2020-12-30 05:49

    As workaround, you can add pseudo groups to the each test with name, equals test method or test class via annotation transformer

    public class TestNGAnnotationTransformer implements IAnnotationTransformer {
    
    @Override
    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        if (testMethod == null || annotation == null) {
            return;
        }
    
        String pseudoGroupClass = testMethod.getDeclaringClass().getSimpleName();
        String pseudoGroupMethod = pseudoGroupClass + "." + testMethod.getName();
    
        String[] existingGroups = annotation.getGroups();
        String[] extendedGroups;
        if (existingGroups == null) {
            extendedGroups = new String[] { pseudoGroupClass, pseudoGroupMethod };
        } else {
            List tmp = new ArrayList();
            for (String group : existingGroups) {
                tmp.add(group);
            }
            tmp.add(pseudoGroupClass);
            tmp.add(pseudoGroupMethod);
            extendedGroups = tmp.toArray(new String[0]);
        }
    
        annotation.setGroups(extendedGroups);
    }
    

    }

    and use it in your testng.xml

    
    
    
        
            
                
                     
                    
                    
                    
                
            
    
            
                
            
        
    
        
           
        
    
    

提交回复
热议问题