Reputation: 3955
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?
Upvotes: 10
Views: 7631
Reputation: 3955
Since I've asked this question, the wording in the documentation has been clarified and explains the behaviour much better now.
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() { // ... } }
Upvotes: 8
Reputation: 1144
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.
Upvotes: 3