简体   繁体   中英

How can I run all the dataProvider entries in one class in parallel?

I set up my tests where each row in the dataProvider creates a new instance of the test class and runs some tests with the data passed in. I want to have all the tests execute simultaneously, however when I run the tests with the current setup, test a is instantiated and the first method is run, then test b is instantiated and the first method is run, etc. I want to be able to have tests a,b,c all execute at once side by side without waiting for eachother to finish/move in a stepwise fashion.

I've achieved this parallel behavior by creating 3 separate class files with individual dataproviders with one row of unique data and then calling parallel="classes" , but how would I do it all in one class?

public class Class1 {

@DataProvider(name = "provider", parallel = true)
public static Object[][] dataProviderSetup() {
    return new Object[][] { { "a", "1", "first" }, { "b", "2", "second" }, { "c", "3", "third" } };
}

    @Factory(dataProvider="provider")
    public CG_AX_001(String var1, String var2, String var3) {
        this.var1 = var1;
        this.var2 = var2;
        this.var3 = var3;
    }

@Test()
public void f1() {
    //
}
}

    <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

    <suite name="suite1" verbose="1" preserve-order="true" data-provider-thread-count="3">
<test name="test1" preserve-order="true">
    <classes>
        <class name="package.Class1" />
    </classes>
</test>

I think similar question is answered in TestNG parallel Execution with DataProvider .

Go through the post. should solve your problem.

cheers

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