0

I have a table with 2 rows and 34 columns. 3 of the columns should be null. When using assertionMode = NON-STRICT, I can specify 34-3=31 columns in my after.xml file, and DBUnit will realize that the 3 missing columns are supposed to be null. DBUnit ensures that the 2 rows and 34 columns in the table precisely match the 2 rows and 31 columns in my after.xml, and any columns I did not specify in after.xml (3 columns) will be assumed to be null which DBUnit verifies as well.

NON_STRICT no longer works, though, if I want to ensure that I have exactly 2 rows, no more no less (for example, if the table does have the 2 rows specified in the after.xml, it will pass the test regardless of if I have more rows or not).

So, I figured I should use assertionMode = DEFAULT. When I do this, the error I get is something like "expected columns is 34, but found 31 in table". It only found 31 because I only specified 31 in my after.xml. The other 3 are null, so I left them out of the after.xml per DBUnit docs. DEFAULT seems to make DBUnit expect 34 columns to be specified in my after.xml regardless of if they're null or not, am I missing something?

I have tried roundabout methods, like specifying a query to get me the 31 columns rather than the 34 (3 columns are null) and using the results of that query to compare to my after.xml. I have also just counted up the number of rows and ensured that I have 2 rows. But those seem to be roundabout methods.

Is there a way to specify columns as null in DBUnit other than leaving them out in my after.xml since DEFAULT doesn't seem to like that?

What is the proper way to specify columns as null in DBUnit with assertionMode = DEFAULT?

cptwonton
  • 500
  • 3
  • 16
  • What does "NON_STRICT no longer works" mean? Do you mean a newer version of dbUnit has broken this feature, or something else? If this is a regression, create a bug report and a PR with a test proving the problem (and a fix if you can!). https://sourceforge.net/p/dbunit/bugs/ https://sourceforge.net/p/dbunit/code.git/ci/master/tree/ – Jeff Mar 06 '18 at 07:06
  • Non_strict is functionally fine, it just isn’t appropriate anymore for what I need. Specifically, I need to ensure the two rows defined in after.xml are the only two rows present in that table, which non_strict does not do but default does. However, my method of handling null columns by leaving them out of the after.xml no longer works for default whereas it did for nonstrict. – cptwonton Mar 06 '18 at 14:45

1 Answers1

0

I have tried roundabout methods,... am I missing something?

To have dbUnit ignore columns from comparison, use an excluded columns table:

ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(filteredTable, excludeColumns);

See Ignoring some columns in comparison

Is there a way to specify columns as null in DBUnit other than leaving them out in my after.xml since DEFAULT doesn't seem to like that?

To have dbUnit insert nulls into database tables, use the ReplacementDataSet and setup a null replacement object, e.g. [NULL]. See ReplacementDataSet.

Jeff
  • 956
  • 8
  • 10