Question: How can I execute certain range of change-units in integration tests ?
Example of the problem: I have three change-units: X
,Y
,Z
(with order
set to: 1
, 2
, 3
). I have integration tests T1
for X
, Y
and T2
for Z
. How can I execute only migrations X
and Y
in test T1
(and "skip" Z
) ?
My solution: I see only two ways.
Assume that each test would have its own runner (like we have in MongockIntegrationTestBase#mongockBeforeEach
):
Each migration file (or a group of files) should be put in one package. And the runner would have addMigrationScanPackage
specified (to narrow down test to only those migrations that are found in that package). In this case we would have package P1
with migrations X
and Y
and package P2
with Z
, so it would be:
runnerBuilder.addMigrationScanPackage("P1");
return runnerBuilder.buildRunner();
Instead of the package, we would use ChangeUnit#systemVersion
and execute runner with properties: SystemVersionable#setStartSystemVersion
and SystemVersionable#setEndSystemVersion
. In this case we would have systemVersion
in X
,Y
,Z
set to 1
,2
,3
and before running the test T1
we would have:
runnerBuilder.setStartSystemVersion("1");
runnerBuilder.setEndSystemVersion("2");
return runnerBuilder.buildRunner();
Both solutions are not satisfactory for me.
SystemVersion
is not intended for that purposeChangeUnit#order
would have to go in parallel with ChangeUnit#systemVersion
, and that's not a good approachIs there any other way I can solve that problem ?
That's a weird case, as you either want to run the entire migration or performing an unit test only in one change unit, which you can do by just running the method annotated with @Execution
.
However, a workaround to achieve that is something similar to your first solution. Create your own runner, but instead of passing the package, you can pass the list of classes directly with addMigrationClasses(List<Class<?>> classes)
or addMigrationClass(Class<?> clazz)