I use liquibase to set up my database schema. I disable hibernate to create anything. Because of that, my import.sql is ignored. Is there any way to configure spring boot or liquibase or any other part to load test data after liquibase has created the tables?
If you need something crude (ie, not for actual data migrations), you can use Spring's JDBC initializer in Spring Boot . In a nutshell, you'll need to:
data-test.sql
to load your data, and place it in your src/main/resources
directory. For different environments, just use the naming convention data-{platform}.sql
applications-test.properties
to src/main/resources
with the following: spring.datasource.platform=test # this actives data-test.sql above spring.datasource.continueOnError=???? # depends on your needs
spring.datasource.platform=test # this actives data-test.sql above spring.datasource.continueOnError=???? # depends on your needs
application-test.properties
during your testing, make sure "test" is one of the profiles that's active during your integration test. One way to do this is to annotate your test class with @ActiveProfiles({"test", ...})
. The simplest way seems to load the data with liquibase. You can do it with a normal Changeset (XML or JSON) or a Changeset in SQL-Format . The most common way is to load CSV-Data or run an existing SQL-File .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.