如何在 TestNG 中將多個組合併為單一測試?


藉助於測試組功能,我們可以將多個組合併為 TestNG 中的單一測試。

示例

包含組的 Testng xml 檔案。

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Tutorialspoint Test">
   <test name = "Regression Cycle 1">
      <groups>
         <run>
            <include name = "QuestionAnswer"/>
         </run>
         <run>
            <include name = "Jobs"/>
         </run>
      </groups>
      <classes>
         <class name = "TestParam" />
      </classes>
   </test>
</suite>

若要從測試用例集合執行一組測試用例,我們必須在 testng xml 檔案中定義 <groups>。此處,testNG xml 包含多個組 QuestionAnswer 和 Jobs,以便與單一測試關聯。

示例

@Test(groups={"QuestionAnswer"},{"Jobs"})
public void preparation(){
   System.out.println("Preparation module is verified");
}

在 Java 類檔案中,具有組 QuestionAnswer 和 Jobs 的測試方法與測試方法 preparation() 關聯。

上次更新時間: 11-06-2020

1K+ 瀏覽量

開啟您的職業生涯

完成課程獲得認證

開始
廣告