I want mock data for integration tests by liquibase changeset, how to make that to not affect real database? I found partial idea from here, but I am using springboot and I hope there is simpler solution.
Running the generate-changelog command Instead of using a properties file, you can pass the necessary information from the command line. Note: If you want to create an SQL changelog file, add your database type name when specifying the changelog file: liquibase --changelog-file=mychangelog.
Integrating Liquibase into your Spring Boot application is extremely easy. You just have to add the Liquibase Core to your classpath. That's all you need to do. The Liquibase integration will automatically load the master changelog file from the db changelog directory.
Running via Maven From the root of the liquibase repository, run mvn test which will build the project and run all the tests. If any tests failed, you'll see it say “BUILD FAILED” at the end and the “T E S T S” section will list the failing tests.
Assume production changeset placed inside resources/db/changelog/changes, and there is a db.changelog-master.yaml in /db/changelog with following config
databaseChangeLog:
- includeAll:
path: db/changelog/changes
Place the testing changset inside test/resources/db/changelog/testchanges and create db.changelog-master.yaml in test/resources/db/changelog with following config
databaseChangeLog:
- includeAll:
path: db/changelog/changes
- includeAll:
path: db/changelog/testchanges
The test should pick up all changeset in two paths and run
You can use liquibase's context parameter. For example create changeset which will have inserts loaded from sql file and specify the context for it. Something like this:
<changeSet id="test_data_inserts" author="me" context="test">
<sqlFile path="test_data.sql" relativeToChangelogFile="true" />
</changeSet>
and in spring boot's application.properties
for test specify the property liquibase.contexts=test
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With