testng运行失败,继续执行
2017-08-31 14:21
337 查看
1.重写断言类
2.编写监听断言类
3.测试类
结果如下
public class Verify { public static StringBuffer verificationErrors= new StringBuffer();; public static void verifyTrue(boolean o) { try { Assert.assertTrue(o); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void verifyFalse(boolean o) { try { Assert.assertFalse(o); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void verifyEquals(Object expected, Object actuals) { try { Assert.assertEquals(expected, actuals); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void verifyEquals(Object expected, Object actuals, String message) { try { Assert.assertEquals(expected, actuals, message); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void assertEquals(String actual, String expected, String message) { try { Assert.assertEquals( actual, expected, message); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void assertEquals(String actual, String expected) { try { Assert.assertEquals( actual, expected); } catch (Error e) { verificationErrors.append(e.toString()); } } public static void tearDown() { String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { Assert.fail(verificationErrorString); } } }
2.编写监听断言类
public class ListenerVerify implements IInvokedMethodListener { @Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { // TODO Auto-generated method stub if (method.isTestMethod()) { Verify.tearDown(); } } @Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { // TODO Auto-generated method stub } }
3.测试类
@Listeners( {ListenerVerify.class}) public class TestVerify { @Test public void test(){ Verify.assertEquals("1", "1"); Verify.assertEquals("1", "2"); Verify.assertEquals("1", "3"); } }
结果如下
相关文章推荐
- JAVA结合testng断言verify(断言失败不中断继续执行)
- JAVA结合testng断言verify(断言失败不中断继续执行)
- JAVA结合testng断言verify(断言失败不中断继续执行)
- “附加数据库失败,版本为661,无法打开,支持655版本...”和“无法执行脚本,没有足够的内存继续执...”
- 很感谢这篇文张【已解决】Makefile:xxx: recipe for target xxx failed +【顺带搞懂了】如何忽略makefile执行过程中的某些命令的错误而得以继续运行
- Win7下VS2008安装cocos2d-2.0-x-2.0.4模板时, 运行InstallWizardForVS2008.js文件执行失败的解决办法
- 对InvokeAction简略分析了解验证失败为什么Action还会继续执行
- 让java程序在后台一直执行(例如putty关闭后后台程序继续运行)
- 让java程序在后台一直执行(例如putty关闭后后台程序继续运行)
- Makefile:xxx: recipe for target xxx failed +【顺带搞懂了】如何忽略makefile执行过程中的某些命令的错误而得以继续运行
- c++ mian函数运行完之后,继续执行
- NDK编译可执行文件在Android L中运行显示error: only position independent executables (PIE) are supported.失败问题解决办法。
- “附加数据库失败,版本为661,无法打开,支持655版本...”和“无法执行脚本,没有足够的内存继续执...”
- c#怎样让程序运行出错仍继续执行【原】
- 【译】SQL Server误区30日谈-Day1-正在运行的事务在服务器故障转移后继续执行
- android 终端运行 vim / vi 命令执行失败 busybox解决之
- robot framwork 失败用例继续执行
- [SoapUI] 如何让某个步骤的Assertion失败之后继续执行后面的步骤
- 让java程序在后台一直执行(例如putty关闭后后台程序继续运行)
- 跳过一些坑,一张图弄明白TestNG多用例执行添加监听失败截图