简体   繁体   中英

running same test with different dataprovider in testng

For example:

  • Data provider 1: dataA
  • Data provider 2: dataB, dataC
  • Data provider 3: dataD, dataE, dataG

So my test takes in a data provider. But I want it to chose different data provider for different test type depending on test group. For example if I am running group "smoke" then I want to use data provider 1, if I am running group "sanity" then I wanted to run data provider 1 and data provider 2, and If I am running group "regression" then I want it to run data provider 1, 2 and 3.

Is this possible? If so can you please provide the information or point me to documentation or something that could help.

Currently my work around is to have 3 different test for each of the group and then I can select which data provider to use. I can also combine data provider.

The problem with my work around is that all 3 test are exactly same the thing that is different is the group and the data provider.

thanks!

What about to use one data provider which returns different data - based on current test group:

@DataProvider(name = "myDataProvider")
public Object[][] testDataProvider(ITestContext context) {
    List<String> includedGroups = Arrays.asList(context.getIncludedGroups());

    if(includedGroups.contains("myGroup")) {
        return dataA;
    }
    else if (includedGroups.contains("myOtherGroup")) {
        return dataBC;
    }

    //...
}

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