I use DbUnit along with Unitils, which works great most of the time.
Today I found a strange problem.
Situation:
- I use Hibernate and have an identifier with a "increment" generator:
<id name = "Id">
<generator class = "increment" />
</id>
- I am preparing a test data set where the maximum id is 5.
- I use a clean insert loading strategy.
- I have two test methods
test1 and test2 , each of which adds one row to this table. - After the
test1 method, the newly added row has id = 6. - After the
test2 method, the newly created line has id = 7.
Everything is in order, and I understand why this is so. However, this is a problem in terms of service. If I ever add a third testing method between them, test2 will end unexpectedly, even if nothing changes, simply because the string will get a different identifier.
Anyway, can I get DbUnit or Hibernate to calculate the next id value before each test method?
java unit-testing junit hibernate dbunit
Ula Krukar
source share