如何在springboot中创建用于集成测试的liquibase变更集?

问题描述:

我想要通过liquibase变更集进行集成数据测试的模拟数据,如何使其不影响真实数据库?我从

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文件中加载插入内容,并为其指定上下文.

Hi 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.

类似这样的东西:

<changeSet id="test_data_inserts" author="me" context="test">
    <sqlFile path="test_data.sql" relativeToChangelogFile="true" />
</changeSet>

并在用于测试的弹簧靴application.properties中指定属性liquibase.contexts=test.

and in spring boot application.properties for test specify property liquibase.contexts=test.