我找到了 an answer对于 junit,但需要 testng 的解决方案。有什么比编写自己的 for 循环更有用的想法吗?
最佳答案
List
比较不需要单独的方法。可以通过 org.testng.Assert#assertEquals(Object, Object)
比较两个列表。
如果两个列表a
和b
是非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/