I have a unit test that inserts rows, and I'd like DBUnit to automatically clean up those rows afterwards (DBUnit does not initially insert those rows - that's purely the responsibility of the code being tested). The table whose rows are being inserted have multiple columns, and a 1-column primary key. I've defined the XML dataset as the following, even though there are multiple columns in tableTest:
However, without having specified to DBUnit anywhere that columnA is the primary key, my JUnit test method annotated with @After does a DatabaseOperation.DELETE.execute(...) and successfully removes the added in row! How does it do this? I figured it might use JDBC metadata, but that's not mentioned anywhere in the DBUnit documentation.
I figured maybe it removes every column that matches the values in the XML file (i.e. delete from tableTest where columnA="10001"). But when I tried the above test specifying only a non-primary key instead of columnA in the XML file, I get the following:
So what is going on - how does DBUnit know what rows(s) to remove, when it doesn't insert those same rows before that test executes?