4

How can I ignore the comparison of some columns using ExpectedDataSet annotation?

  • I use dbunit API.
Code Enthusiastic
  • 2,827
  • 5
  • 25
  • 39
Dali
  • 135
  • 2
  • 13

2 Answers2

10

In spring using spring-test-dbunit, you can write:

@ExpectedDatabase(value="yourdataset.xml", assertionMode=DatabaseAssertionMode.NON_STRICT)

and omit the columns on "yourdataset.xml"

ref: http://springtestdbunit.github.io/spring-test-dbunit/

Paizo
  • 3,986
  • 30
  • 45
  • 1
    my case is that I have two tables which one table has foreign key constraint to the other, and the reference is the other table's field 'id' which will auto increment every insert, and cannot be omitted for this reference relation, and when I run unit test, the comparisonFailure occured for the id is not match(expect 1 but real value is more than 1 and increasing), what to do with this case? – NullPointer Oct 11 '17 at 10:59
0

I have the same probleme, ommiting column is not working for my case. I have two tables organizations and customers, customer email should be unique by organization.

<organizations
            id='4e332e3d-fc13-4e39-91dd-53825c71b9b2'
    ...
/>
<organizations
            id='ca9484a6-70a3-4b7d-b6da-4528152684bf'
    ...
/>
 <individual_customers
            id="9892be6a-ca10-49eb-9616-33cf03a24e63"
            organization_reference="4e332e3d-fc13-4e39-91dd-53825c71b9b2"
 />

when instering the new customer, I expect to have a new customer, but I dont know the new inserted id. I get this error message value (table=individual_customers, row=0, col=id) expected:<[null]> but was:<[47d89697-c2fe-42a0-8d9c-fc4b5b0aaaa0]>

  • 1
    I found the solution just after posting this comment, I removed the id from the fist customer. documentaion of `NON_STRICT_UNORDERED` ``` Specified columns must match in all rows, e.g. specifying 'column1' value without 'column2' value in one row and only 'column2' value in another is not allowed - both 'column1' and 'column2' values must be specified in all rows. ``` – ABDERRAHIME FARHANE Jul 26 '22 at 19:56