We will cover here how to do DAO integration test when you have spring boot application with PostgreSQL DB and liquibase for schema versioning , last time we have explained how to do the same without liquibase using embedded PostgreSQL in this post but this time we will do the same but using docker with test containers which will apply your liquibase changes and making sure you DAO integration test has the same environment as production database environment if you are using docker for your data base in production .
Beside spring boot starter dependencies we will need to add liquibase and test containers dependencies , whole maven pom file can be viewed in Github code
Your liquibase database simple master configuration will be in your resources source set which will create simple customer table with file name changelog-master.xml .
Spring boot DAO integration test configuration :
We will highlight the important sections , the whole configuration java file can be viewed into the github code : DbConfig.java
Where when you run the test from your IDEA , you should see the spring boot application is started properly and the docker image of the postgreSQL is started with liquibase changes applied so you can trigger your DAO integration test a production like situation .
The PostgreSQL docker image starting , off-course you need docker kernel installed in our machine to be able to test the same :
the docker image start for postgreSQL test container
And liquibase changes being applied as you can see in the console logs :
liquibase changes being applied for customer table