为 List<List<Integer>> 类型编写 Junit5 测试用例
Writing Junit5 test cases for List<List<Integer>> type
JUNIT 5 是否提供任何内置断言来测试类型为 List<List<Integer>>
的输出,或者需要循环它并比较每个元素
您可以简单地使用正常的assertEquals()
方法来比较这些对象。 List<>
接口定义了 equals()
方法(被 assertEquals()
使用如下:
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.
JUNIT 5 是否提供任何内置断言来测试类型为 List<List<Integer>>
的输出,或者需要循环它并比较每个元素
您可以简单地使用正常的assertEquals()
方法来比较这些对象。 List<>
接口定义了 equals()
方法(被 assertEquals()
使用如下:
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 elementse1
ande2
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 theequals
method works properly across different implementations of theList
interface.