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
addMigrationScanPackagespecified (to narrow down test to only those migrations that are found in that package). In this case we would have packageP1with migrationsXandYand packageP2withZ, so it would be:runnerBuilder.addMigrationScanPackage("P1"); return runnerBuilder.buildRunner();Instead of the package, we would use
ChangeUnit#systemVersionand execute runner with properties:SystemVersionable#setStartSystemVersionandSystemVersionable#setEndSystemVersion. In this case we would havesystemVersioninX,Y,Zset to1,2,3and before running the testT1we would have:runnerBuilder.setStartSystemVersion("1"); runnerBuilder.setEndSystemVersion("2"); return runnerBuilder.buildRunner();
Both solutions are not satisfactory for me.
- The first one looks weird to create a separate package per migration file
- The second one is slightly better, but:
SystemVersionis not intended for that purpose- Ordering
ChangeUnit#orderwould have to go in parallel withChangeUnit#systemVersion, and that's not a good approach
Is 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)oraddMigrationClass(Class<?> clazz)