我們在 TestNG 中使用正則表示式來處理一組以特定模式命名的測試方法。示例 Testng xml 檔案。所有以“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.*) 實現的。
我們可以透過將一組測試用例包含在執行中來執行特定的一組測試用例。示例帶有組的 Testng xml 檔案。要從測試用例集中執行一組測試用例,我們必須在 testng xml 檔案中定義。這裡 testNG xml 包含要在執行中包含的組 Smoke。示例@Test(groups={"Smoke"}) public void Payment(){ System.out.println(“Payment is successful”); }在 Java 類檔案中,只有具有 Smoke 組的測試方法才能從整個迴歸套件中執行。