[英]How to skip a data set (on error) from TestNG data provider?
我正在嘗試使用TestNG(當然還有dataprovider注釋)執行數據驅動的測試。
我的情況是這樣的...
使用dataProvider具有2個dim數組。 (我正在使用它從Excel中讀取,但為簡潔起見,避免使用它)。
@DataProvider(name = "featureTest") public Object[][] dataSets() throws Exception { return new Object[][] { {"TC_01", "testuser_1", "Test@123", "ABC Street", "123-456-7899" }, { "TC_02", "testuser_1", "Test@123", "PQR Street", "222-456-7899" } }; }
在@Test方法中,根據功能流程有幾種方法-
@Test(dataProvider = "featureTest") public void executeTest(String... data) throws Exception { try{ feature_1.execute(data); feature_2.execute(data); feature_3.execute(data); feature_4.execute(data); } catch(Exception e){ log.error("Error has occured"); } }
現在我的主要問題是,在我在@Test中指定的這4(n)個方法中的任何地方都可能發生功能錯誤。
如果任何一種方法都有例外,我需要“跳過”特定的數據集並繼續進行下一個。 例如:在執行TC_01的過程中,feature_2.execute()中發生了異常,它不應執行feature_3和feature_4方法。
注意:我嘗試使用@ BeforeMethod,@ AfterMethod來處理它,但仍然會通過我要避免的不需要的方法。
在此先感謝您的幫助/投入和歉意,盡管這個問題很簡單,但可以解釋!!!
我能想到的一種方法是工廠方法,
您的測試課
class Test{
Data data;
Test(Data){
this.data=data;
}
@Test
test1(){
feature_1.execute(data);
}
@Test
test2(dependsOnMethods ="test1"){
feature_2.execute(data);
}
@Test(dependsOnMethods ="test2")
test3(){
feature_3.execute(data);
}
@Test(dependsOnMethods ="test3")
test4(){
feature_4.execute(data);
}
}
而在您的工廠班級
class Factory{
@Factory(DataProvider = "myDP")
public Object[] factoryTest(Data data){
new Test(data);
}
@DataProvider
public Object [][] myDP(){
enter code here
}
}
非常簡單。 使用退貨!
使用條件或嘗試catch評估失敗,然后使用return語句;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.