Running test methods one after another in TestNG

前端 未结 3 1352
有刺的猬
有刺的猬 2021-01-23 05:44

I m using Eclipse + Selenium WebDriver + TestNG

This is my class structure :

class1
{
@test (invocation count =4)
method1()

@test (invocation count =4)
         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-23 06:23

    Of course there is a lot of methods to make it. An Example:

    import java.lang.reflect.Method;
    
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.Test;
    
    public class ABC {
    
        @Test(invocationCount=12)
        public void uno(){
            System.out.println("UNO");
        }
        @AfterMethod()
        public void sec(Method m){
            if(m.getName().equals("uno"))
            System.out.println("SEC");
        }
    }
    

    And suite:

    
    
    
      
        
          
              
                  
              
          
        
       
    
    

    Remeber, if you use dependsOnMethod then thoes method will be executed after all invocation. For example:

    @Test(invocationCount=3)
    public void uno(){
        System.out.println("UNO");
    }
    @Test(dependsOnMethods={"uno"})
    public void sec(){
    
        System.out.println("SEC");
    }
    

    with:

    
    
    
      
        
          
              
                  
                     
              
          
        
       
    
    

    will give:

    UNO
    UNO
    UNO
    SEC
    
    ===============================================
    Suite
    Total tests run: 4, Failures: 0, Skips: 0
    ===============================================
    

    And if you test your tests please use verbose ="3" in suite conf. example:

    
    

    Cause this is turning on full logs.

提交回复
热议问题