TestNG: How can I run same test case multiple times?

后端 未结 8 1264
你的背包
你的背包 2020-12-30 20:22

I want to run a test case multiple times. Is that configurable in the testng.xml? If I add a loop in the test method, then the results of each run will not be a

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 20:43

    public class ProcessTest implements ITest {
    
    
        protected ProcessData processData;
    
        @Test
        public void executeServiceTest() {
            System.out.println(this.processData.toString());
        }
    
        @Factory(dataProvider = "processDataList")
        public RiskServiceTest(ProcessData processData) {
            this.processData = processData;
        }
    
        @DataProvider(name = "processDataList", parallel=true)
        public static Object[] getProcessDataList() {
    
            Object[] serviceProcessDataList = new Object[10];
    
        for(int i=0; i<=serviceProcessDataList.length; i++){
            ProcessData processData = new ProcessData();
            serviceProcessDataList[i] = processData
        }
    
    
            return serviceProcessDataList;
        }
    
        @Override
        public String getTestName() {
    
            return this.processData.getName();
        }
    }
    

    By using @Factory and @DataProvider annotation of TestNG you can execute same test-case multiple times with different data.

提交回复
热议问题