Executing multiple test sequentially with different parameters testng

后端 未结 3 1038
有刺的猬
有刺的猬 2021-01-07 08:42

I was trying to run multiple test with different parameters sequentially using data providers, basically the scenario is suppose there are 5 test completing a test flow and

3条回答
  •  天涯浪人
    2021-01-07 09:27

    So my concern is that all test should run first with first parameter air and then again all test should execute with next parameter "earth"

    Here is the output that i got for the input "air" and "earth"

    Test-1 with data: Air
    Test-2 with data: Air
    Test-1 with data: Water
    Test-2 with data: Water
    

    Test Class - RandomTest

    public class RandomTest {
        private String str = "";
    
        public RandomTest(String str) {
        this.str = str;
        }
    
        @Test
        public void firstTest() {
        System.out.println("Test-1 with data: "+str);
        }
    
        @Test
        public void secondTest() {
        System.out.println("Test-2 with data: "+str);
    }}
    

    Factory class - SampleFactory

    public class SampleFactory {
    @Factory(dataProvider="dp")
    public Object[] createInstances(String str) {
        return new Object[] {new RandomTest(str)};
    }
    
    @DataProvider(name="dp")
    public static Object[][] createData() {
        return new Object[][] {
                new Object[] { new String("Air") },
                new Object[] { new String("Water") }
        };
    }}
    

    Run the class SampleFactory from testng.xml, Please note: group-by-instances="true"

    
    
        
            
        
    
    
    

    Ref: http://testng.org/doc/documentation-main.html#factories
    Ref: http://java.dzone.com/articles/testng-run-tests-sequentially

提交回复
热议问题