如何在springboot中为集成测试创建liquibase变更集? [英] How to create liquibase changeset for integration tests in springboot?
问题描述
我想要通过 liquibase 变更集进行集成测试的模拟数据,如何使其不影响真实数据库?我从 here,但我正在使用 springboot,我希望有更简单的解决方案.
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.
推荐答案
可以使用 liquibase 的 context 参数.例如,创建将从 sql 文件加载的插入并为其指定上下文的变更集.像这样的:
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>
并在 Spring Boot 的 application.properties
中进行测试,指定属性 liquibase.contexts=test
.
and in spring boot's application.properties
for test specify the property liquibase.contexts=test
.
这篇关于如何在springboot中为集成测试创建liquibase变更集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!