JAVA單元測試框架-9-testng.xml管理依賴

鹿少年發表於2020-12-02

在testng.xml裡配置依賴管理,先寫個測試用例

 @Test(description="測試分組" ,groups= {"operation"})
    public void TestGroupAdd() {
        System.out.print(String.valueOf(11+12));
    }
    @Test(description="測試分組" ,groups= {"operation","Animal"})
    public void TestGroupAnimal() {
        System.out.printf("animal 動物");
    }
    @Test(description="測試分組" ,groups= {"Animal"})
    public void TestGroupCat() {
        System.out.printf("cat 喵喵");
    }
    @Test(description="測試分組" ,groups= {"laguage"})
    public void TestGroupLaguage() {
        System.out.printf("chinese 漢語");
    }

testng.xml配置 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
    <test verbose="2" preserve-order="true" name="D:/IdeaProject/interfaceRestAssured">
        <groups>
            <define name="groups" >
                <include name="operation"></include>
                <include name="Animal"></include>
                <include name="laguage"></include>
            </define>
            <dependencies>
                <group name="Animal" depends-on="laguage"></group>
            </dependencies>
        </groups>
        <classes>
           <class name="TestNg.TestGroup"></class>
        </classes>
    </test>
  <!--  <listeners>
        <listener class-name="report.ExtentReport"></listener>
    </listeners>-->
  <!-- 這是reportNG的監聽類-->
    <listeners>
         <listener class-name="org.uncommons.reportng.HTMLReporter"></listener>
         <listener class-name="org.uncommons.reportng.JUnitXMLReporter"></listener>
     </listeners>
</suite>

執行結果:

相關文章