Issue
Spring Boot 1.4 has brought many good improvements for testing.
I am unclear of the purpose of href="http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/TestConfiguration.html" rel="noreferrer">@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?
Solution
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() { // ... } }
Answered By - jhyot
Answer Checked By - Marie Seifert (JavaFixing Admin)