I need an idea/tip how to use DbUnit to assert IDs, generated by a database (e.g. MySQL's auto increment column). I have very simple case, which yet, at the moment, I find problematic:
2 tables: main
and related
. main.id
column is an auto-increment. Related table has a foreign key to it: related.main_id
-> main.id
. In my test case my application does insert multiple entries into both tables, so the dataset looks similar to this:
<dataset>
<main id="???" comment="ABC" />
<main id="???" comment="DEF" />
<related id="..." main_id="???" comment="#1 related to ABC" />
<related id="..." main_id="???" comment="#2 related to ABC" />
<related id="..." main_id="???" comment="#3 related to DEF" />
<related id="..." main_id="???" comment="#4 related to DEF" />
</dataset>
As the order, how the inserts will be performed is unclear - I cannot simply clear/truncate the table before the test and use predefined IDs in advance (e.g. "ABC" entry will come at first so it gets ID 1
and "DEF" as 2nd - gets 2
). If I write test such way - this will be wrong - with a bit of luck sometimes it may work and in other cases not.
Is there a clean way how test such cases? As I still want to assert that entries were created and linked properly in DB, not only that they exists (if I would simply ignore the auto-increment columns).