i currently study more in deep the @TestConfiguration and i wonder why using this combo..
@TestConfiguration
public class TestConfig {
// some bean definitions
and then using
@SpringBootTest
@Import(TestConfig.class)
class UsingImport {
@Autowired
ConfigBean configBean;
// some code
and not using the classic @Configuration, in the src/test, as it is totally legal do it. Why is the real purpose of @TestConfiguration, as we can do the same with @Configuration ?
Am i wrong ?
The key difference between
@TestConfigurationand regular@Configurationis that the classes marked with the usual@Configurationannotation are included in the application context automatically because scanning recognises this annotation. Whereas classes labelled with@TestConfigurationare not subject to scanning, and you will have to import the configuration for each test manually, giving you the flexibility to control the number of beans needed for that test