Gibt es eine Möglichkeit, eine einzelne Bean oder einen Wert aus einer Spring-Konfiguration für einen oder mehrere Integrationstests zu ersetzen?Java-basierte Spring Context-Konfiguration für Tests überschreiben
In meinem Fall habe ich die Konfiguration
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"foo.bar"})
public class MyIntegrationTestConfig {
// everything done by component scan
}
die für meinen Integrationstest verwendet wird
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
public class MyIntegrationTest {
// do the tests
}
Jetzt mag ich einen zweiten Satz von Integrationstests haben, wo ich eine Bohne ersetzen durch ein anderer.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
public class MySpecialIntegrationTest {
// influence the context configuration such that a bean different from the primary is loaded
// do the tests using the 'overwritten' bean
}
Was ist der einfachste Weg, dies zu erreichen?