Top level @TestConfiguration picked up by @SpringBootTest without @Import when it referenced from another module
See original GitHub issueMain reason for @TestConfiguration is to allow having configuration without picking it up by auto scanning.
But my test with @SpringBootTest and without any @Import loads definitions from top-level class marked by @TestConfiguration.
| | +--- org.springframework.boot:spring-boot-starter-test: -> 1.5.3.RELEASE
| | | +--- org.springframework.boot:spring-boot-test:1.5.3.RELEASE
| | | \--- org.springframework:spring-test:4.3.8.RELEASE
@TestConfiguration is defined in Core module and @SpringBootTest class in module that uses Core test module via Gradle’s testCompile project (...).
Documentation says:
When placed on a top-level class, @TestConfiguration indicates that classes in src/test/java should not be picked up by scanning.
Is dependency for module via testCompile project a reason for a problem? How can I mark a class to be eligible for @Import without being auto-scanned?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
46. Testing - Spring
When placed on a top-level class, @TestConfiguration indicates that classes in src/test/java should not be picked up by scanning. You can then import...
Read more >Spring Boot: @TestConfiguration Not Overriding Bean During ...
I try to do a test with #TestConfiguration placed on a top-level class and with #Import(MyTestConfiguration.class) and without # ...
Read more >Testing with Spring Boot's @TestConfiguration Annotation
The @TestConfiguration annotation is a useful aid for writing unit tests of components in a Spring Boot application.
Read more >version 1.3 - Spock Framework Reference Documentation
Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful...
Read more >A Quick Guide to @TestPropertySource - Baeldung
Spring brings many features to help us with testing our code. Sometimes we need to use particular configuration properties in order to set...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In case somebody happens across this issue, we ran into a similiar problem to the one described by @gavenkoa.
In our case, we found that someone had mistakenly included an unnecessary
@ComponentScanannotation on one of the app configuration classes. Probably just a reflex from the pre@SpringBootApplicationdays.Anyway, removing the unneeded
@ComponentScanresolved the issue.If test is configured with
@SpringBootConfigurationplus@ComponentScaninstead of@SpringBootApplication, thenexcludeFiltersneed to be added in order to avoid picking up@TestConfigurations without explicit@Import: