Hi I faced with a problem or verification of datasets in dbunit. Lets imagine I have such a table
//initial-dataset.xml
<dataset>
<user id="1" ...other fields />
<user id="3" ...other fields />
<user id="4" ...other fields />
<user id="2" ...other fields />
</dataset>
And I have such test class:
@DatabaseSetup("initial-dataset.xml")
public class UserTest {
//tests for find operations
@Test
@ExpectedDatabase("expected-data.xml")
public void testCreateUser() {
// test for create
}
}
I want to verify that new field was added in database and I do not want to list all data from initial-dataset.xml
in my expected-dataset.xml
.
I tried to add DatabaseAssertionMode.NON_STRICT
but with this attribute dbunit still checkes that expected dataset contains exactly same number or rows from User table as in actual database.
Another soution is add @DatabaseSetup
with such xml for create operation:
<dataset>
<user />
</dataset>
In this case dbunit will clean-up everything from user
table before run the test and in this case my expected-data.xml
should contains only result of my test execution. But in this case it is hard to verify different corner cases that can happen in real scenarious.
Another solution is use unitils(some kind of wrapper under dbunit) but this library has really strange concept of @Dataset and @ExpectedDataset
My concern is for example another developer will change smth or add new entry in initial-dataset.xml
then he need to update all expected-datasets with this new field.