I would like to propose an annotation that can be used to conditionally enable/disable (disable!) a configuration class when Spring Boot is running in an automated testing environment such as JUnit.
My problem: disable scheduling in test
But I guess there are a number of other possible scenarios. Maybe I have another: if I have a bean that represents a REST client, I would like to make sure my app never performs remote invocations in JUnit.
Currently, Spring supports @TestConfiguration
annotation to annotate a configuration class to be used only in JUnit environment. That's terribly cool! But no opposite exists.
I will likely use profiles in my projects, as I already have a profile to disable scheduling.
But offering this feature in the framework could be cool as well.
There are obviously 35 ways to do the same thing, and @ConditionalOnNonTesting
is just one of the 866 possible names.
What about it?
Comment From: wilkinsona
Thanks for the suggestion. I'm not too keen on the idea of providing an annotation specifically for this purpose. Specifically, I don't like the idea of having a test-specific annotation in main application code. Also, as you've said, there are already other ways to achieve the same thing. I'll flag this for team attention to see what the rest of the team thinks.
Comment From: snicoll
Same here. There are many ways to achieve the same thing (profile being the most obvious). Having said that, we did change metrics export to only happen in-memory with users having to opt-in for it using AutoConfigureMetrics
on the test that requires it. Scheduling is not as clear-cut as pushing metrics to an external system though.
Comment From: philwebb
I agree with @wilkinsona, I'd prefer not to have a dedicated @ConditionalOnNonTesting
annotation. I prefer our current arrangement where spring-boot-autoconfigure
doesn't know about spring-boot-test
concerns.
Comment From: wilkinsona
The team are in agreement that this isn't something that we want to implement. Thanks anyway for the suggestion, @djechelon.