I have some integrtion tests that create an HSQL db from JPA entities. This all works well apart from the auto increment id. These seem to be stored between tests and not reset. For example if I add two items in test 1 then the id value in HSQL for these two rows is 1 and 2. In my set up I then destroy the db. In test 2 I add one item and the id is 3 and not back to 1. I am using Spring as the transaction manger and to wire up all my dependencies. Does any one know what could be causing this?
I do not want to check ids per se but I do find this annoying.
Thanks in advance
This is expected. auto-increment IDs are handled by the database, so, unless you drop the tables and recreate them before each test (which you shouldn’t do), the IDs will keep incrementing.
Just don’t rely in absolute values for the IDs in your tests. Get the ID values from the entities that you create when setting up your test case.