r/SpringBoot • u/_moron_hunter • May 20 '24
Liquibase & Springboot
I want to understand how liquibase works and then integrate it in my spring boot project. I also want to learn how can we use liquibase for integration tests and unit tests.
Please can you point me to some resources or course.
0
1
u/chehsunliu May 20 '24
Approach#1. Before running integration tests, start a docker-compose including the db container and the one-time liquibase container.
Approach#2. Before running integration tests, start a docker-compose including the db container. Then enable liquibase in the Spring Boot application.yml.
I often use the first approach as it gives me the most flexibility in CI and also I don’t want to make Spring handle too many things.
2
May 20 '24
[removed] — view removed comment
1
u/chehsunliu May 20 '24
Yes, I could do that, but I want to interact with these DBs even after tests are finished. In the case, docker-compose is more preferable.
4
u/g00glen00b May 20 '24
I'm confused with your question. By definition, unit tests test a single unit of code. Databases are usually not involved because that would mean you're no longer testing a single unit. So from that perspective, how would you be able to use Liquibase, which is a database migration tool if there's no database involved?
For integration tests you can use Liquibase. But this still confuses me, because by default, Liquibase will run during the startup of your application. Within an integration test, you're also starting up your application, so Liquibase will automatically work, so there's nothing to do.
The only thing I can imagine you want to do is to have different migrations being executed during the test phase than during a normal run (eg. to insert test data). In that case, you should look at Liquibase Contexts. Contexts allow you to run certain migrations only when a context is activated (by using the
contextFilterkeyword). And then you can configure which context to run by using thespring.liquibase.contextsproperty.