简体   繁体   中英

How can I run the same test cases for all the data in a list using testng?

I am using data provider and test ng to run the same test multiple times using different values from a list. However, I have several tests and I want them all to run one by one so Test 1 -> Test 2 -> Test 3, for each item in the list. Right now Test 1 is running 4 times for all 4 elements in the list, and then Test 2 ->Test 3.

    @DataProvider
    public Object[][] data() throws CsvValidationException, IOException, URISyntaxException {
        ...get list..
        Object[][] element = new Object[list.size()][1];
        for (int i = 0; i < list.size(); i++) {
            element[i][0] = list.get(i);
        }
        return element;

    }

    @Test(dataProvider = "data",priority = 1)
    public void test(Element element) {
        System.out.println("test1");
    }
    
    @Test(priority=2)
    public void test2() {
        System.out.println("test2");

    }

So I want the output to be 'test1' 'test2'... 'test1' 'test2'...'test1''test2' not 'test1'..'test1'..'test1'..'test2'.

The output order depends on the priority. Did you check the same priority in both tests?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM