Question

I am using @Profile Spring annotations to choose between embedded, standalone and container managed data sources. In order to choose 'embedded' my integration tests are annotated to activate the appropriate profile:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes={TestConfigWrapper.class})
@ActiveProfiles({"EMBEDDED_DB"})
public class SomeIntegrationTest {

The problem is that I would like to move '@ActiveProfiles' into TestConfigWrapper, but doing this doesn't get picked up and the application context won't load any DataSources.

This means I have to annotate every integration test with an @ActiveProfile which effectively means it becomes integration test boiler-plate and could easily hamper future refactoring.

Is there a way I can do this using java config?

Was it helpful?

Solution

Per comment from Hippooom use an abstract class to configure tests:

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={WebAppInitializer.class})
@ActiveProfiles({Profiles.EMBEDDED_DB})
public abstract class ProfiledIntegrationTest {

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top