zoukankan      html  css  js  c++  java
  • testng运行失败,继续执行

    1.重写断言类

    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");    
        }
    }

    结果如下

  • 相关阅读:
    C++编程练习(3)----“实现简单的栈的顺序存储结构“
    C++编程练习(2)----“实现简单的线性表的链式存储结构“
    C++编程练习(1)----“实现简单的线性表的顺序存储结构“
    Django--登录实例
    Django--model模型绑定_数据库操作
    Django--初始化
    web框架--MVC、MTV
    CSS--箭头
    CSS--抽屉(dig.chouti.com)页面
    jQuery--加一行减一行
  • 原文地址:https://www.cnblogs.com/longronglang/p/7458083.html
Copyright © 2011-2022 走看看