-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support @MockitoBean
in @Configuration
classes
#33934
Comments
We have encountered the same problem. The reason why we define We could use a base class for tests but that goes against the extensible design of JUnit 🤔 |
Everything in the issue queue points to I have nothing agains a better implementation, but this is not a "toy" to play around, neither is the migration "a little thing". For us, this is huge i feeling pushed into a playground in this area feels like being let down. This field needs to be rock solid - and when it is, deprecation can come in. Expamples
there are other issues in the queue pointing at similar, severe issues. I beg you, please roll back the deprecation until the actual target to migrate to is "ready for battle". |
@MockitoBean
on @Configuration
classes
I can confirm I'm running into the same issues when moving from spring boot The test's that are failing due to missing beans are set up almost exactly like @tobias-lippert 's example. With a I also confirmed that adding the mock bean declarations to the test class (as well as alternatively a base abstract test class) directly fixes the problem (like @tobias-lippert mentioned). |
Same here. We also define |
I mentioned this on the Spring Boot repo spring-projects/spring-boot#43282 . |
I'm a Spring Boot maintainer and only speaking for the Boot team below.
There's a tricky balance to strike here. Replacing
IMO, rolling back the deprecation would be counter-productive. Instead, I'd like to try to reassure folks by noting that functionality deprecated in Spring Boot 3.4 won't be going away any time soon. We have Spring Boot 3.5 planned for May 2025 and it won't be removed in that release. Assuming the same pattern as previous releases, OSS support for Spring Boot 3.5 would then be provided until May 2026. Please keep the constructive feedback coming and then address the deprecation either through a suppression or by using an alternative, even if it is one where you feel there's room for improvement. |
The important first
I understand the critic above is harsher in it's tone, but i really try to keep it constructive in the first place (and i gave suggestions / opinions on how to improve it)
I'am following the project rather open-minded and i never heard of the |
I was talking in general terms about our experience with getting a sizeable portion of the user base to try out a new feature, not specifically the introduction of |
That's fair - missed all of those. That one is one me and surely proves you point of not getting substantial feedback if it is not thrown into our faces. Yes, but i have a "but". Use the deprecation as a tool, for a annotation that is used 100+ in the code base (triggering a warning for each), for this specific case, was just not a good choice. For us, it is rather 1000+ and this means, every CI checking testing logs needs massive scrolling, not to talk about proper deprecation warnings which are entirely hidden now. Constructively, i would love to offer something like
So honestly, i have no constructive option on how to fix what has been enforced here while If you ask me, you could have make the entire Do not get me wrong, things move on, break and needs migration. That is what it is and we all have to move. This is fair. I understand, it's probably too late, but at least take my feedback as bring attention to changing such sensible topics. This is not "spring session redis" or "spring security SAML", "jpa" only affecting parts of spring boots ecosystems. This changed affected all ecosystems at once, all of them. And this makes this a sensible one. Thank you for your feedback and comment, really appreciated to at least have a dialog - maybe we do not agree, but still, thank you for being responsive. |
When your policy is to compile with |
Same frustrations here, and it's a bit ironic since both Spring Framework and Spring Boot use those as well 🙂:
Using suppressions tactically here and there is OK, but for non-trivial projects this can easily mean hundreds of suppressions which is really not cool. I understand and agree that it's harder to get quality feedback without doing deprecations, but at the same time there appear to be quite a few common cases that developers rely on and don't have a clear migration path so I feel like this could easily turn out to be a prohibitively expensive upgrade for some projects (which also translates into less feedback). So I'm personally in the camp that would like to see the deprecation rolled back, at least until clear migration path for common use cases is provided. |
@MockitoBean
on @Configuration
classes@MockitoBean
in @Configuration
classes
Versions
Spring Boot 3.4.0
Spring Framework 6.2.0
Hi Spring team,
While upgrading our apps to Spring Boot 3.4.0, I've encountered that some of our tests don't start because the application context cannot be created due to a missing bean dependency that should exist as mocked bean.
We define some
MockitoBeans
in a config class annotated with@TestConfiguration
and import this class using@Import
.When I define a MockBean instead, the tests succeed.
You can find an example that reproduces the behavior here: https://github.com/tobias-lippert/spring-mockitobean-test-configuration-import-bug
The test passes on the branch mockbean-working and fails on the branch mockitobean-not-working.
I couldn't find anything in the docs pointing out that this should no longer work. If this is not a bug, but intended behavior please advise how to fix this.
The easiest, but not the prettiest workaround I've found is getting rid of the separate
TestConfigurations
and placing allMockitoBeans
in the actual test class.The text was updated successfully, but these errors were encountered: