如何在 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 = "Test Cycle">
      <classes>
         <class name = "TestRegularExpression" />
         <methods>
            <exclude name= “Payment.*”/>
         </methods>
      </classes>
   </test>
</suite>

所有以 Payment 開頭的測試方法都將從迴歸套件中排除。

示例

@Test
public void PaymentHistory(){
   System.out.println("Payment history validation is successful”);
}
@Test
public void Login(){
   System.out.println("Login is successful”);
}
@Test
public void PaymentDefault(){
   System.out.println("Payment default verification is successful”);
}

Login() 將被執行,但所有以 Payment 開頭的將從執行中排除。這是使用正則表示式(Payment.*)實現的。

更新日期:2020 年 6 月 11 日

1K+ 瀏覽

開啟你的職業

完成課程獲得認證

開始使用
廣告