You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to create Liquibase migrations which populate your test database, you have to create a test changelog which also includes the production changelog.
210
+
If you want to create Liquibase migrations which populate your test database, you can leverage https://docs.liquibase.com/reference-guide/changelog-attributes/what-are-contexts[Liquibase contexts].
211
+
See also the related https://www.liquibase.com/blog/contexts-vs-labels[blog post].
211
212
212
-
First, you need to configure Liquibase to use a different changelog when running the tests.
213
-
One way to do this is to create a Spring Boot `test` profile and put the Liquibase properties in there.
214
-
For that, create a file named `src/test/resources/application-test.properties` and put the following property in there:
213
+
In practical terms, this translates into adding a `context:@test` attribute to changesets containing test data, for example:
insert into project (id, name) values (1, 'Spring Boot');
237
221
----
238
222
239
-
This changelog will be used when the tests are run and it will not be packaged in your uber jar or your container.
240
-
It includes the production changelog and then declares a new changeset, whose `runOrder: last` setting specifies that it runs after all the production changesets have been run.
241
-
You can now use for example the https://docs.liquibase.com/change-types/insert.html[insert changeset] to insert data or the https://docs.liquibase.com/change-types/sql.html[sql changeset] to execute SQL directly.
242
-
243
-
The last thing to do is to configure Spring Boot to activate the `test` profile when running tests.
244
-
To do this, you can add the `@ActiveProfiles("test")` annotation to your javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] annotated test classes.
223
+
And using `spring.liquibase.contexts=test` in environments where you would like changesets containing test data to be applied.
0 commit comments