テストでテストメソッドから例外をスキップしようとしています。データプロバイダを使用してExcelからデータを取得し、テストをスキップしたい条件に基づいて、スキップ例外がスローされますが、これらのテストケースも合格として表示されます。次のように私のコードは次のとおりです。スキップ例外をスローすることによってテストメソッドから例外をスキップしようとしましたが、テストケースがまだ通ります
@Test(dataProvider = "postProperty")
public static void postProperty(Object testCaseNo , Object propertyFor , Object testCaseFlag , Object propertyType , Object propertyCode){
int ppTestCaseNo = (int) testCaseNo;
String ppPropertyFor = propertyFor.toString();
String ppTestCaseFlag = testCaseFlag.toString().trim();
String ppPropertyType = propertyType.toString();
int ppPropertyCode = (int) (double) propertyCode;
boolean propertyIdFlag = true;
try {
if (ppTestCaseFlag.equalsIgnoreCase("Yes")){
GenericFunctions.excelDataForTestCase(ppTestCaseNo);
driver = new ChromeDriver();
Robot robot = new Robot();
String browserType = workSheet.getRow(ppTestCaseNo).getCell(5).getStringCellValue().trim();
switch (browserType) {
case "Deployment" :
driver.get("http://deployment.magicbricks.com/postproperty/post-property-for-sale-rent/residential-commercial");
break;
case "Live" :
driver.get("http://post.magicbricks.com/postproperty/post-property-for-sale-rent/residential-commercial");
break;
case "Staging" :
driver.get("http://staging.magicbricks.com/postproperty/post-property-for-sale-rent/residential-commercial");
break;
case "NewMB" :
driver.get("http://newMB.magicbricks.com/postproperty/post-property-for-sale-rent/residential-commercial");
break;
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
if (ppPropertyType.equalsIgnoreCase("Multistorey Apartment")){
boolean propertyIdPostedFlag = PostProperty.functionPostPropertyMultiStoreyApartment(ppPropertyType , ppPropertyCode ,driver , robot, ppTestCaseNo ,log);
Assert.assertEquals(propertyIdFlag, propertyIdPostedFlag);
}
else{
boolean propertyIdPostedFlag =PostProperty.functionPostPropertyOtherPropertyType(ppPropertyType , ppPropertyCode ,driver , robot, ppTestCaseNo ,log);
Assert.assertEquals(propertyIdFlag, propertyIdPostedFlag);
}
}
else if (ppTestCaseFlag.equalsIgnoreCase("No")){
throw new SkipException("Skipping test case for "+ppPropertyType);
}
} catch (Exception e) {
e.printStackTrace();
}
}
必要はありません。 catch(Exception ...)例外がinstanceOf SkipExceptionかどうかをチェックします。真の場合は再びそれを投げます。しかし、他の例外を処理することができます – Grasshopper
@グラスホッパーはい、あなたは絶対に正しいですか?しかし、これは意味をキャッチして、再び投げ込むのですか?私は考えている可能性があります個々の例外を個別にメッセージを個別に処理する最良の方法は、実際に例外が発生した既知の... :) –
ありがとう...それは働いた – Deepak