繁体   English   中英

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

[英]Is there any way to use Spring Boot, Liquibase and an sql-script for integration tests?

我使用liquibase来设置我的数据库模式。 我禁用hibernate来创建任何东西。 因此,我的import.sql被忽略。 在liquibase创建表之后,有没有办法配置spring boot或liquibase或任何其他部分来加载测试数据?

如果您需要粗略的东西(即,不是实际的数据迁移),您可以在Spring Boot中使用Spring的JDBC初始化程序 简而言之,您需要:

  1. 创建一个data-test.sql来加载数据,并将其放在src/main/resources目录中。 对于不同的环境,只需使用命名约定data-{platform}.sql
  2. 使用以下命令将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. 要在测试期间激活application-test.properties ,请确保“test”是集成测试期间处于活动状态的配置文件之一。 一种方法是使用@ActiveProfiles({"test", ...})注释您的测试类。

最简单的方法似乎是使用liquibase加载数据。 您可以使用普通的Changeset(XML或JSON)或SQL格式Changeset来完成此操作 最常见的方法是加载CSV数据或运行现有的SQL文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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