简体   繁体   English

有没有办法使用Spring Boot,Liquibase和sql脚本进行集成测试?

[英]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: 简而言之,您需要:

  1. create a 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
  2. add 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/resourcesspring.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
  3. to active the 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM