TestNG测试用例的序列

时间:2014-10-28 14:30:51

标签: testng

我正在进行测试集成并使用测试,在这里我需要运行具有多个测试数据的测试用例序列。这里测试用例之间存在依赖关系。

公共类MyTestCase扩展了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;
    }

}

}

这里我需要运行test1,test2和test3作为序列,并提供传递数组的数据元素。根据以上样本,我期待输出如下。

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

但我得到了以下输出

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

有没有办法克服这个问题?

1 个答案:

答案 0 :(得分:1)

使用group by instances运行测试 创建一个如下所示的套件xml并设置group-by-instances =" true",使用它运行测试。

<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>