DBUnit Boolean

After learning SpringBoot, I wanted to continue working with integration tests using (DBUnit and SpringTestDBUnit). Throughout the process, everything went well until it came up with setting values ​​for boolean data columns in the data set. (The contents of the dataset are given below)

<?xml version="1.0" encoding="UTF-8"?> <dataset> <Client code="0001" name="client_one" /> <Client code="0002" name="client_two" /> <Client code="0003" name="client_three" active="false" /> <Client code="0004" name="client_four" /> </dataset> 

Adding the attribute active="false" to the client record [code = 0003], my integration tests fail and showing me this message Exception processing table name='Client' , which led to the fact that the client record [code = 0001] violates a restriction other than a null column.

After fixing the error (on the DBUnit_For_Boolean_Columns_Attempt_One branch), indicating the values ​​for the active column on all records (which is slightly different from the specification), this worked. But my goal was to successfully complete the integration tests with the above dataset.

Question: how can integration tests using the dataset above be successful? . It's currently hard for me to implement the solutions, so I created the Bitbucket repository so you can see and help in real time.


change list

  • Changes in 2015/02/04

    • Improve the content of questions
    • Bitbucket repository added
+6
source share
1 answer

(I had a different answer here, which was due to a complete erroneous diagnosis of the problem, as I missed the fact that the OP used FlatXmlDataSet ).

From the FlatXmlDataSet documentation:

Table metadata is derived from the first row of each table by default. Remember that DbUnit might think that a table skips some columns if the first row of this table has one or more null values.

There seems to be a problem here, since the first entry does not indicate a value for active . To avoid this problem, you can use the DBUnit column discovery property, which essentially makes DBUnit fully read XML before displaying the table structure:

 FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setInputSource(new File("path/to/dataSet.xml")); builder.setColumnSensing(true); // HERE! IDataSet dataSet = builder.build(); 

Alternatively, if you yourself do not create a builder and do not want to manipulate it, just make sure that each element has an active column, especially the first one:

 <dataset> <client code="0001" name="client_one" active="false" /> <client code="0002" name="client_two" active="true" /> </dataset> 
+1
source

Source: https://habr.com/ru/post/981534/


All Articles