TestNG依赖于来自不同类的forOnGroups for testng.xml文件

时间:2017-05-11 06:45:58

标签: testng

如何在testng.xml文件中使用dependsOnGroups方法,因此类1方法失败,类2不应该运行。

第1课:

public class GetDataForChannelAPI{

@Test(dataProvider = "getData", dataProviderClass = DataUtil.class, priority = 2,groups={"getVillagesAndPincodes"})

public void channelAPI_GetPickUpLocation(LinkedHashMap<String, String> data) {


//Added some code.

}


}

第2课:

public class VerifyChannelAPI{

@Test(dataProvider = "getData", dataProviderClass = DataUtil.class, priority = 3, dependsOnGroups = {
            "getVillagesAndPincodes" },groups={"channelAPITest"})

public void channelAPI_Franchise_NoSpace(LinkedHashMap<String, String> data) {

//Added some code here
}

}

请帮帮我。谢谢。

请查看下面的xml代码。

    <groups>
        <run>
            <include name="GetDataForPackageAPI.getFranchiseIdsGJ" />
            <include name="GetDataForPackageAPI.getFranchiseIdsRJ" />
            <include name="GetDataForPackageAPI.getFranchiseIdsMH" />
            <include name="GetDataForPackageAPI.getOrderIdsGJ" />
            <include name="GetDataForPackageAPI.getOrderIdsRJ" />
            <include name="GetDataForPackageAPI.getOrderIdsMH" />
            <include name="GetDataForPackageAPI.getPackageIdsGJ" />
            <include name="GetDataForPackageAPI.getPackageIdsRJ" />
            <include name="GetDataForPackageAPI.getPackageIdsMH" />
        </run>
    </groups>
    <classes>
        <class name="com.agroex.packageapi.testsuite.VerifyPackageAPI"></class>
        <class name="com.agroex.packageapi.testsuite.GetDataForPackageAPI"></class>
    </classes>

</test> <!-- Test -->

2 个答案:

答案 0 :(得分:1)

A类:GetDataForPackageAPI

@Test(dataProvider = "getData", dataProviderClass = DataUtil.class, priority = 10, groups = {
            "getFranchiseIdsGJ" })
    public void packageAPI_GetFranchiseIdListFor_GJ(LinkedHashMap<String, String> data) {
//Some code
}

B类:VerifyPackageAPI

@Test(dataProvider = "getData", dataProviderClass = DataUtil.class, priority = 13, dependsOnGroups = {
            "getFranchiseIdsGJ" })
    public void packageAPI_VerifyParameter_FranchiseIdGJ_OpsUser(LinkedHashMap<String, String> data) {
        try {
//Add some code
}

XML文件:

<test name="Package API Test" parallel="tests" thread-count="15" >
        <classes>
            <class name="com.agroex.packageapi.testsuite.VerifyPackageAPI"></class>
            <class name="com.agroex.packageapi.testsuite.GetDataForPackageAPI"></class>
        </classes>

    </test>

答案 1 :(得分:0)

我发布的代码中没有任何错误;除了它没有格式化:)如果问题是如何构建您的XML文件:

<suite name="PackageAPItest">      

<test name="SmokeTest">

<groups>
<run>
<include name="getVillagesAndPincodes">
</run>
</groups> 

<classes>
<class name="com.agroex.packageapi.testsuite.GetDataForPackageAPI"></class> 
<class name="com.agroex.packageapi.testsuite.VerifyPackageAPI"></class>         
</classes>  

</test>
</suite>

祝你好运!