I use Flyway to manage the state of my DB in my Spring MVC application.
I have it configured in my servlet context XML file exactly as the recommend in their docs
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="..."/>
...
</bean>
<!-- The rest of the application (incl. Hibernate) -->
<!-- Must be run after Flyway to ensure the database is compatible with the code -->
<bean id="sessionFactory" class="..." depends-on="flyway">
...
</bean>
I'd like to do two things in my JUnit tests -
Once, before ALL tests, drop and recreate the database and let it re-migrate. This creates a clean database for each test suite.
Before each test, clean all the DB tables. In other frameworks (e.g. RSpec/Rails) I've accomplished this by running DB statements transactionally so they rollback at the end of the test. Not sure what the best practice is in the Spring MVC world.
I have no clue where to really begin with implementing the above, so any guidance is appreciated.
Thanks!