I am using Spring boot 2.3, and have the following test.
// imports
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(Suite.class)
@Suite.SuiteClasses({
AuthControllerTests.class, //test case 1
ReferenceDataControllerTests.class, //test case 2
ManualUploadDataControllerTests.class // test case 3
})
public abstract class ApplicationTests {
private static final PostgreSQLContainer postgreSQLContainer;
static {
postgreSQLContainer = new PostgreSQLContainer<>("postgres:12")
.withDatabaseName("tescontainers")
.withUsername("testcontainers")
.withPassword("testcontainers");
postgreSQLContainer.start();
}
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
}
}
The 3 test classes (AuthControllerTests, ReferenceDataControllerTests, ManualUploadDataControllerTests) are as below:
@AutoConfigureMockMvc
public class AuthControllerTests extends ApplicationTests {
..
..
}
@AutoConfigureMockMvc
public class ReferenceDataControllerTests extends ApplicationTests {
..
..
}
@AutoConfigureMockMvc
public class ManualUploadDataControllerTests extends ApplicationTests {
..
..
}
Basically these tests uses the same Postgres DB initiated by ApplicationTests and they all run successfully without issues.
However, I want to run these test is particular order of classes. Hence I tried using Suite.class, but it is not helping. As you can see I provided the order AuthControllerTests, ReferenceDataControllerTests and lastly ManualUploadDataControllerTests. But it is running the ManualUploadDataControllerTests first and then AuthControllerTests and then ReferenceDataControllerTests.
Any way I can run these in needed order? I don't want to combine all the tests in one class and then use @TestMethodOrder to define the order of methods.