I have a BaseTest class that consists of several tests. Each test must be performed for EACH profile I. List
I was thinking about using parameterized values such as:
@RunWith(Parameterized.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public abstract class BaseTest {
@Autowired
private TestRepository test;
private TestContextManager testContextManager;
public BaseTest(String profile) {
System.setProperty("spring.profiles.active", profile);
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
Collection<Object[]> params = new ArrayList<>();
params.add(new Object[] {"h2-test" });
params.add(new Object[] {"mysql-test" });
return params;
}
@Before
public void setUp() throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
}
@Test
public void testRepository() {
Assert.assertTrue(test.exists("foo"))
}
How can I tell Spring to run each test with these different profiles? In fact, each profile will talk to different data sources (inside h2 memory, external mysql, external oracle, ..), so my repository / data source needs to be reinitialized.
, @ActiveProfiles (...), BaseTest ActiveProfile. , . BaseTest, . , :
- BaseTest (@ActiveProfiles ( "mysql" ))
- FooClassMySQL ( BaseTest)
- FooClassH2 (@ActiveProfiles ( "h2" ))
- BarClassMySQL ( BaseTest)
- BarClassH2 (@ActiveProfiles ( "h2" ))