Search code examples
spring-bootspring-data-jpaintegration-testingliquibase

Integration tests with incomplete liquibase changelogs


I maintain an older, spring boot based system, where the underlying database was initialised und subsequently changed with database-scripts.

At some point, development switched to using liquibase: a few changesets were implemented and now all database changes are to be done via changeset.

This now raises problems with integration-tests that use the persistence layer, like @DataJpaTests or @SpringBootTests: liquibase tries, on startup, to apply its changesets. But since theses changesets reference tables that exist in the productive database, but where never created or modified by liquibase, it is - of course - unable to execute changesets that alter these non existant tables in the test database.

The only reason this used to "work" is because - until today - there were never any @DataJpaTests or @SpringBootTests.

However, I am now in situation, where I would like, very much, to allow the use of, at least, @DataJpaTests. Is there any way of doing that without adding changesets that might influence the productive database?


Solution

  • There are two options:

    1. disable liquibase for your @DataJpaTest(properties={"spring.liquibase.enabled=false")
    2. create separate liquibase changelog(s) for your test