org.dbunit.database - junit.framework.ComparisonFailure - 每次运行时表顺序都不同

时间:2017-03-13 02:32:50

标签: java database postgresql scala junit

运行测试和table3的顺序总是不同的,因此AssertEquals不起作用。

val expectedDataSet = new CsvDataSet(new File(BatchJobIntegrationTest.getTestResource("folder/expected/")))
val actualDataSet = connection.createDataSet(Array(
  "table1",
  "table2",
  "table3"
))

Assertion.assertEquals(expectedDataSet, actualDataSet)

尝试但没有奏效:

Assertion.assertEquals(new SortedDataSet(expectedDataSet), new SortedDataSet(actualDataSet))

1 个答案:

答案 0 :(得分:1)

原来关键是问题,这有助于:

val expectedTable = expectedDataSet.getTable("table")
val actualTable = actualDataSet.getTable("table")

val actualFilteredTable = DefaultColumnFilter.excludedColumnsTable(actualTable, Array("table_id"))
val expectedFilteredTable = DefaultColumnFilter.excludedColumnsTable(expectedTable, Array("table_id"))
//Assertion.assertEquals(expectedTable, actualFilteredTable)

val expectedColumns = expectedFilteredTable.getTableMetaData().getColumns()
val sortedExpected = new SortedTable(expectedFilteredTable, expectedColumns)
val sortedActual = new SortedTable(actualFilteredTable, expectedColumns)
Assertion.assertEquals(sortedExpected, sortedActual)