Exclude TestConfiguration classes even when running outside a spring-test managed context
See original GitHub issueSpinoff of https://jira.spring.io/browse/SPR-9090
IDEs such as Eclipse commingle /src/test/java and /src/main/java into a single classpath. As such, @TestConfiguration classes can be picked up when running the main SpringBootApplication in Eclipse.
Spring Boot Test already has the capability to exclude such configuration classes. Unfortunately, that capability uses the ContextCustomizer hook which is only available inside a spring-test-managed context. Would it be possible to migrate this capability into the core framework such that the TypeExcludeFilters could be leveraged when running a main application?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
How to exclude java configuration class from test context
I have a Java web app with spring boot. When run test I need to exclude some Java config files:.
Read more >Testing - Spring
ContextLoader is a strategy interface for loading an ApplicationContext for an integration test managed by the Spring TestContext Framework. You ...
Read more >Exclude Auto-Configuration Classes in Spring Boot Tests
In this quick tutorial, we'll discuss how to exclude auto-configuration classes from Spring Boot tests. Spring Boot's auto-configuration ...
Read more >Fix No Qualifying Spring Bean Error For Spring Boot Tests
The Spring Bean is not part of the sliced Spring Context ... We can even outsource this test configuration to a dedicated class...
Read more >Testing in Java & JVM projects - Gradle User Manual
Ways to control how the tests are run (Test execution) ... Filtering supersedes the inclusion/exclusion mechanism, but you may still come across the...
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
For future reference for anyone reading this thread, here is the buildship bug for separating runtime and test classpaths.
The pattern I use to get around Eclipse is for any config classes I create for my tests I tag them with
@Profile("NameOfMyTestConfiguration"), and then any test classes which use them I tag with@ActiveProfiles("NameOfMyTestConfiguration"). This ensures that when running my tests only my relevant test classes get picked up, and when running my application none of my test class configuration gets picked up.The other trick I use is to always run my application in Eclipse using the Gradle Buildship plugin
bootRuntask. Gradle will make sure only the correct classes will be picked up.Or you could switch to IntelliJ (which I’ve done over the past few months), then you don’t need to worry at all about it!