简体   繁体   中英

Testng - Looping a dataprovider or a class in Java?

I'm looking for a bit of assistance with my plan layout if possible

Currently what I have is the following which works well:

@dataprovider connects to a mysql database, then stores 300 results into an array @test loops for all 300 entries and all tests pass

What I need, and I'm struggling with is:

After the @test has finished I then need to somehow go back to the dataprovider (with a variable) then run the tests again.

If you imagine a directory structure, I query the database for all categories beginning with A, test the results then re-query the database for categories beginning with B and re-test the outcome.

Not sure how to go about this, so far I've tried to add in a loop into my @dataprovider, so the array have for example 300 A categories, 300 B categories etc. But this was giving me all sorts of issues with the array.

Any ideas how I can achieve this or would I need a separate class for each data query? Mike

Dataprovider can return an Object[][] Array. Did you try something like this:

@DataProvider(name="categoryloader")
public Object[][] createData(){
    return new Object[][]{
            {"CatgoryA",new String[300]},
            {"CatgoryB",new String[300]},
    };
}

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