如何验证测试中的项目列表
我正在编写一个测试用例,其中我确实发送要保存在数据库中的字符串列表。 然后我将从数据库中检索这些内容并验证一切是否正常。
我写了一个
assertNotNull(list)
assertEquals(listSize, response.listSize())
但是我想验证实际内容是否也相同。但是我的assertEquals 失败了,因为返回的字符串列表的顺序不同。
通常你如何验证此类事情?
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 contents 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呃...为什么不通过按字母顺序创建初始列表来强制排序(或使用 排序)然后在 SQL 中使用 ORDER BY 子句?
也就是说,您可能需要迭代列表中的元素并比较它们(因为原始列表中的键和从数据库中检索到的键也可能不同)。
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
that combined with your size verification makes sure that the list is complete and doesn't contain extras.