Hi,
I'm writing some integrations tests in JUnit. What happens here is that when i run all the tests together in a row (and not separately), the data persisted in the database always changes and the tests find unexpected data (inserted by the previous test) during their execution.
So I created a @Before method in my base test class to drop and create the schema between each execution (it's slow, but it should work):
Code:
@Before
public void before() {
Configuration configuration = new Configuration().configure();
SessionFactory sessionFactory =configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
Connection connection = session.connection();
SchemaExport schemaExport = new SchemaExport(configuration, connection);
schemaExport.execute(false, true, true, true);
session.close();
}
But unfortunately it doesn't seem to work. The problem here is that i also need the
auto-increment columns to be
reset, because in my tests i check the IDs of the persisted entities, so that i thought that a drop and create operation would regenerate the columns and, by doing so, reset the auto-increment column of each table between each test execution.
Any tips?
Thanks