I have the following structure;
Main Config Class;
@TestConfiguration
@Import({MainApplication.class, ConfigA.class, ConfigB.class})
public class MainTestConfiguration {
}
And two separate config classes;
@TestConfiguration
public class ConfigA {
@Bean
public EtcDao etcDao() {
// return custom etcDao
}
}
@TestConfiguration
public class ConfigB {
@Bean
public SomeBean someBean() {
// return custom someBean
}
}
And the test is as following;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainTestConfiguration.class)
public class MotherTest {
@Test
public void test() {
// test
}
}
With this structure, my test definitions of the beans EtcDao
and SomeBean
are ignored, and the main context definitions of these beans are used (from MainApplication.class
). But if I include these separate configurations in @SpringBootTest
like @SpringBootTest(classes = {ConfigA.class, ConfigB.class})
, then it works properly. Doesn't @Include
allow the beans in these individual configuration classes to be initialized? Or the culprit is my inclusion of MainApplication.class
together with them, but I need other configuration from it so I had to implement in this manner.