The following snippets loads the application context with the configuration given in TestConfiguration.class
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class TestWithContext {
}
With the following snippet you can include the configuration from BasicConfiguration
and then override it in TestConfiguration
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestWithContext.TestConfiguration.class)
public class TestWithContext {
@Configuration
@Import(BasicConfiguration.class)
public static class TestConfiguration {
@Bean
...
}
}
If you want to use classes annotated with @Component
in your tests, you can use the @ComponentScan(basePackages = "...")
annotation:
public class MyTest {
// ...
@Configuration
@ComponentScan(basePackages = "ch.lihsmi.spring.amqp.byexample.exchanges.direct")
public static class TestConfiguration {
// ...
}
@Component
public static class TestMessageListener {
// ...
}
}
Helped me a lot, thanks!