0
votes

I am working on Test integration and using Testing for that, Here I need to run sequence of test cases with multiple test data. Here test cases has dependencies between each other.

public class MyTestCase extends ISIntegrationTest {

TestBean testbean;

@Factory(dataProvider = "beanProvider")
public MyTestCase(TestBean testbean) {
    this.testbean = testbean;
}

@DataProvider(name = "beanProvider")
public static TestBean[][] beanProvider() {
    return new TestBean[][] { { new TestBean("type1") },
            { new TestBean("type2") } };
}

@BeforeTest(alwaysRun = true)
public void testInit() throws Exception {

}

@AfterTest(alwaysRun = true)
public void atEnd() throws Exception {

}

@Test(alwaysRun = true, description = "test1")
public void test1() {
    System.out.println("test1 : " + testbean.type);
}

@Test(groups = "wso2.is", description = "test2", dependsOnMethods = "test1")
public void test2() throws Exception {
    System.out.println("test2 : " + testbean.type);

}

@Test(groups = "wso2.is", description = "test3", dependsOnMethods = "test2")
public void test3() throws Exception {
    System.out.println("test3 : " + testbean.type);

}

static class TestBean{
    String type;

    TestBean(String type){
        this.type = type;
    }

}

}

Here I need to run test1, test2 and test3 as a sequence with provide data element of passing array. I am expecting output as below according to above sample.

test1 : type1 test2 : type1 test3 : type1 test1 : type2 test2 : type2 test3 : type2

But I am getting following output

test1 : type1 test1 : type2 test2 : type1 test2 : type2 test3 : type1 test3 : type2

Is there any way to overcome this issue ?

1

1 Answers

1
votes

Use group by instances to run the tests Create a suite xml as below and set group-by-instances="true", run the tests using this.

<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="nameOfTheTestFirefox" group-by-instances="true">
    <parameter name="browserName" value="firefox" />
    <classes>
        <class name="com.crazytests.dataproviderissue.MyTestCase" />
    </classes>
</test>