[英]How to Assert No exception thrown TestNG java
大家好 我有一個問題要解決。 我在純 Java 中使用 selenium 並測試 NG。 在測試類中,我想調用一個方法,如果該方法拋出異常,我想使測試失敗。 這是方法:
public void insertAddress2(String address2) throws Exception {}
我想從測試類中調用它,如果它(插入 address2 方法)拋出異常,我希望測試失敗。
這是類測試斷言語句
@Test(groups = {"address"},enabled = true)
public void testAddress() throws Exception {
Assert.assertNotEquals(adderess.insertAddress2("test"),ErrorMessagePermission, "");
}
有人可以建議什么是語法以及如何測試不同類的 insertAddress2 方法中拋出的異常
基本上,即使在測試中,當您想對異常做出反應時,您也必須捕獲它們:
@Test(groups = {"address"}, enabled = true)
public void testAddress() { //no throws decleration required
try {
adderess.insertAddress2("test");
} catch (Exception ex) {
Assert.fail("Exception was thrown!");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.