I’m evaluating LiquiBase for a project based on Maven / Spring Framework / iBatis / PostgreSQL (production db) / … and LiquiBase seems to be very helpful, I thank all the commiters!
For the unit test of the data access components, I’m using HSQLDB (memory) and JUnit to create and to populate a DB before each test (setUp) and clean up at the end (tearDown).
The Spring LiquiBase wrapper doesn’t offer a solution out-of-the-box for this use case because the DB is created when the bean is loaded (only once whereas it should be called between each unit test).
So I call programmatically LiquiBase during the setUp and the tearDown and it works.
- protected void setUp() throws Exception
dataSource = (DataSource)context.getBean("dataSource");
Liquibase liquibase = new Liquibase("src/main/resources/res/cp1/db.changelog.xml", new FileSystemFileOpener(), dataSource.getConnection());
protected void tearDown() throws Exception
Liquibase liquibase = new Liquibase(“src/main/resources/res/cp1/db.clear.xml”, new FileSystemFileOpener(), dataSource.getConnection());
My question is to know if it is a “correct” way of using LiquiBase for unit test and generally to have feedbacks or best practices about the use of LiquiBase for uint tests.