执行以下代码后,testng 报告显示由于 try-catch block 而通过,但如果控件进入 catch block ,我需要使测试失败。
@Test
public void testIt( Method method )
{
Webdriver d1= new FirefoxDriver();
d1.get(http://www.google.com);
String title=d1.getTitle();
String var=Gogle;
System.out.println("start execution!!!");
try {
Assert.assertEquals( title,var );
} catch( Throwable er ) {
System.out.println("Error in method '" + method.getName() + "'.);}
System.out.println("Execution End!!!");
}
}
最佳答案
在catch block 中调用Assert.fail(String message, Throwable Cause) 将您选择的错误消息作为第一个参数,将 catch 中的 Throwable er 作为第二个参数。
关于java - 如何在 testng 报告中使由于 try catch block 而通过的测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24897163/