大家好,我有一个问题想解决。 我使用 selenium 和纯 java 并测试 NG。 在测试类中,我想调用一个方法,如果该方法抛出异常,我想让测试失败。 这是方法:
public void insertAddress2(String address2) throws Exception {}
我想从测试类中调用它,如果它(插入地址2方法)抛出异常,我希望测试失败。
这是类测试断言语句
@Test(groups = {"address"},enabled = true)
public void testAddress() throws Exception {
Assert.assertNotEquals(adderess.insertAddress2("test"),ErrorMessagePermission, "");
}
有人可以建议一下语法是什么以及如何测试不同类的 insertAddress2 方法中是否抛出异常
最佳答案
基本上,即使在测试中,当您想要对异常使用react时,您也必须捕获它们:
@Test(groups = {"address"}, enabled = true)
public void testAddress() { //no throws decleration required
try {
adderess.insertAddress2("test");
} catch (Exception ex) {
Assert.fail("Exception was thrown!");
}
}
关于java - 如何断言 TestNG java 没有抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60827834/