I am using DbUnit together with Unitils, which works great most of the time.
Today I found a strange problem.
Situation is:
- I use Hibernate, and have id with "increment" generator:
<id name="Id"> <generator class="increment"/> </id>
- I prepare test dataset, where maximal id is 5.
- I use clean-insert loading strategy.
- I have two test methods
test1
andtest2
, each adding one row in this table. - After
test1
method newly added row has id=6. - After
test2
method newly created row has id=7.
This is all OK and I get why this is like that. It is a problem from maintenance perspective though. If I ever add third test method between the two, method test2
will suddenly fail even though nothing changed, just because row will get different id.
Is there anyway I can force DbUnit or Hibernate to calculate next id value before each test method?