softassert
时间: 2023-10-01 15:03:09 浏览: 26
SoftAssert是TestNG测试框架中的一个特性。它与硬断言(Assert)相比,具有一些不同的特点。当一个断言失败时,SoftAssert会继续执行测试用例中的其他断言,并在测试用例结束时报告所有断言的失败情况。与硬断言不同的是,SoftAssert不会在断言失败时立即抛出异常停止测试用例的执行。
常用的SoftAssert方法有:
- softAssert.assertEquals(actual, expected):判断两个对象是否相等。
- softAssert.assertNotEquals(actual, expected):判断两个对象是否不相等。
- softAssert.assertNull(object):判断对象是否为空。
- softAssert.assertNotNull(object):判断对象是否不为空。
- softAssert.assertSame(actual, expected):判断两个对象的引用是否相等。
- softAssert.assertNotSame(actual, expected):判断两个对象的引用是否不相等。
- softAssert.assertTrue(condition):判断条件是否为true。
- softAssert.assertFalse(condition):判断条件是否为false。
- softAssert.assertArrayEquals(actual, expected):判断两个数组是否相等。
在使用SoftAssert时,需要在测试用例结束前调用softAssert.assertAll()方法,以便报告所有断言的失败情况。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)