开发者

How to verify list of items in a test

I am writing a test case where I do send a list of Strings to be saved in the database. Then I will retrieve those from database and has to verify that everything is fine.

I have written a

assertNotNull(list) 
assertEquals(listSize, response.listSize())

However I want to verify the actual c开发者_如何学编程ontents are also same. But my assertEquals is failing since the list of strings are not in the same order when they are returned.

How do you verify this type of thing usually?


Er... why not just force the ordering by creating the initial list alphabetically (or use a sort) and then use the ORDER BY clause in SQL?

That said, you may need to iterate through the elements in the list and compare them (as the keys may also be different in your original list and that retrieved from the database).


assuming you have a List expected, which are the strings you expect, you can do

assertTrue (response.containsAll(expected))

that combined with your size verification makes sure that the list is complete and doesn't contain extras.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜