[英]Is there any way to use Spring Boot, Liquibase and an sql-script for integration tests?
I use liquibase to set up my database schema. 我使用liquibase来设置我的数据库模式。 I disable hibernate to create anything.
我禁用hibernate来创建任何东西。 Because of that, my import.sql is ignored.
因此,我的import.sql被忽略。 Is there any way to configure spring boot or liquibase or any other part to load test data after liquibase has created the tables?
在liquibase创建表之后,有没有办法配置spring boot或liquibase或任何其他部分来加载测试数据?
If you need something crude (ie, not for actual data migrations), you can use Spring's JDBC initializer in Spring Boot . 如果您需要粗略的东西(即,不是实际的数据迁移),您可以在Spring Boot中使用Spring的JDBC初始化程序 。 In a nutshell, you'll need to:
简而言之,您需要:
data-test.sql
to load your data, and place it in your src/main/resources
directory. data-test.sql
来加载数据,并将其放在src/main/resources
目录中。 For different environments, just use the naming convention data-{platform}.sql
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
applications-test.properties
添加到src/main/resources
: 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. application-test.properties
,请确保“test”是集成测试期间处于活动状态的配置文件之一。 One way to do this is to annotate your test class with @ActiveProfiles({"test", ...})
. @ActiveProfiles({"test", ...})
注释您的测试类。 The simplest way seems to load the data with liquibase. 最简单的方法似乎是使用liquibase加载数据。 You can do it with a normal Changeset (XML or JSON) or a Changeset in SQL-Format .
您可以使用普通的Changeset(XML或JSON)或SQL格式的Changeset来完成此操作 。 The most common way is to load CSV-Data or run an existing SQL-File .
最常见的方法是加载CSV数据或运行现有的SQL文件 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.