I expected adding @Execution(ExecutionMode.SAME_THREAD)
to work but it doesn’t. Other tests run in parallel. Is there some annotation to synchronize test threads and make them actually wait?
As an example I would expect all other tests hold until AaInitialStateITCase
is finished. But it doesn’t it runs dummies in parallel.
So basically I want some tests to be executed alone, especially initialization.
This is what actually happens with forkCount = 4
:
- Running pl.mol.molnet.initsaas.Dummy2ITCase
- Running pl.mol.molnet.initsaas.Dummy1ITCase
- Running pl.mol.molnet.initsaas.AaInitialStateITCase
- Running pl.mol.molnet.initsaas.Dummy3ITCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 27.68 s — in pl.mol.molnet.initsaas.Dummy1ITCase
- Running pl.mol.molnet.initsaas.Dummy4ITCase
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 s — in pl.mol.molnet.initsaas.Dummy4ITCase
Example ITCase
/**
* Init main database objects.
* @author Maciej Nux Jaros
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration({"/testContextPg.xml"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Execution(ExecutionMode.SAME_THREAD) // cannot be run in paralel
public class AaInitialStateITCase extends TestDatabaseCleaner {
@BeforeAll
public void mockTenantService() throws SaasException {
initAll();
}
@Test
public void testInit_shouldInitTenants() throws Exception {
assertNotNull(tenant1);
assertNotNull(tenant2);
}
}
/**
* Artificial test exhausting threads.
* @author Maciej Nux Jaros
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration({"/testContextPg.xml"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class Dummy1ITCase extends TestDatabaseCleaner {
@Test
public void test_forthreads() throws Exception {
assertEquals(2, 1+1);
}
}