java - 如何断言列表与testng相等?

标签 java testng

我找到了 an answer对于 junit,但需要 testng 的解决方案。有什么比编写自己的 for 循环更有用的想法吗?

最佳答案

List 比较不需要单独的方法。可以通过 org.testng.Assert#assertEquals(Object, Object) 比较两个列表。

如果两个列表ab 是非null,调用Assert.assertEquals(a, b) 表示随后将调用 a.equals(b)

java.util.List#equals 是您所需要的,如 javadoc 中所述:

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

关于java - 如何断言列表与testng相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33480936/

相关文章:

java - 用手电筒重播摩尔斯电码?

java - Firebase 数据检索 java

java - 如何在 Selenium WebDriver 中使用 @FindBy 注解

java - TestNG + Mockito,如何测试抛出的异常和模拟调用

selenium-webdriver - 用于成组执行TESTNG测试的Gradle命令语法

java - 即使使用 google play 核心库更新应用程序后,应用程序更新仍在继续

java - 如何重置 JTable

java - Android JavaCV 困境,创建 IplImage 时在方法 'draw' 内部抛出 NoClassDefFoundError

java - jenkins与maven集成问题

java - 在 TestNG.xml 中使用组时忽略 @AfterMethod 调用