Spring Boot 1.4 has brought many good improvements for testing.
I am unclear of the purpose of @TestConfiguration
. It doesn't seem to work as expected.
I thought that if I use @TestConfiguration
on a top-level class under /src/test/java
that it gets picked up by a @SpringBootTest
test (see here). But this seems not to be the case. If I instead use @Configuration
then it gets correctly picked up.
Did I misunderstand? Is the manual wrong? Is there a bug in the Spring Boot code?
Since I've asked this question, the wording in the documentation has been clarified and explains the behaviour much better now.
Per the new documentation:
When placed on a top-level class,
@TestConfiguration
indicates that classes insrc/test/java
should not be picked up by scanning. You can then import that class explicitly where it is required, as shown in the following example:@SpringBootTest @Import(MyTestsConfiguration.class) class MyTests { @Test void exampleTest() { // ... } }
whenever we have used <context:component-scan base-package="some.package" />
or @ComponentScan
. it scans all . for that to prevent Spring Boot provides @TestComponent
so that they should not be picked up by scanning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With