封装的断言。

 1 package com.baidu.www;

 import org.testng.Assert;
/*
* 封装断言
*/
public class assertion {
static boolean flog = true; public static void verifyassert(Object actual, Object expected) {
try {
Assert.assertEquals(actual, expected);
} catch (Error e) {
// TODO: handle exception
flog = false;
}
} public static void verifyassert(Object actual, Object expected, String message) {
try {
Assert.assertEquals(actual, expected, message);
} catch (Error e) {
// TODO: handle exception
flog=false;
} }
}

调用方法,判断错误,继续执行

 @Test
public void test1() {
System.out.println("测试用例一");
int actual;
int expected;
actual = 1;
expected = 2;
assertion.flog = true;
for (int i = 0; i < 3; i++) {
System.out.println("断言开始1");
assertion.verifyassert(i, expected, "测试连个字符是否相同");
System.out.println("断言结束");
// 结果是tur;要修改
}
Assert.assertTrue(assertion.flog); //结果改为flog,错
05-11 13:04