문제

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?

도움이 되었습니까?

해결책

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 {

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top