DB Unit should ignore order of rows

送分小仙女□ 提交于 2019-11-29 22:29:18

问题


Is there a way telling DB-Unit to ignore the order in which rows should be compared? My problem is, that I do not know in which order the rows will be written to the database, but DB-Unit forces me to give an ordered list.

What I want dbunit to do is:

  • check that number of rows in database and expected dataset match (Solved: Works out of the box
  • check whether each rows will be found only once in the result-set. (NOT SOLVED)

Any ideas?


回答1:


Solved this issue for me. I'm sorting the rows of the actual and expected tables. Therefore I use all columns which can be found in expected table. This approach might result in problems if the table you are checking is large but in my case it is not. :-)

Column[] expectedColumns = expectedTable.getTableMetaData().getColumns();
ITable sortedExpected = new SortedTable(expectedTable, expectedColumns);
ITable sortedActual = new SortedTable(actualTable, expectedColumns);
Assertion.assertEquals(sortedExpected, sortedActual);


来源:https://stackoverflow.com/questions/13142365/db-unit-should-ignore-order-of-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!