Skip to content
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 Mockito with @MockBean and @SpyBean in AOT-processed tests #32195

Closed
philwebb opened this issue Aug 30, 2022 · 14 comments
Closed

Support Mockito with @MockBean and @SpyBean in AOT-processed tests #32195

philwebb opened this issue Aug 30, 2022 · 14 comments
Labels
for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement

Comments

@philwebb
Copy link
Member

Currently Mockito doesn't work with native tests. See spring-attic/spring-native#1561 and spring-attic/spring-native#1063 for more details.

For now, we can disable the ResetMocksTestExecutionListener, but it would be nice if we could make Mockito work.

@philwebb philwebb added this to the 3.x milestone Aug 30, 2022
@philwebb philwebb added the type: enhancement A general enhancement label Aug 30, 2022
philwebb added a commit that referenced this issue Aug 31, 2022
Add a guard for `ResetMocksTestExecutionListener` so that it is
not applied when running in a native image.

See gh-32195
@sdeleuze
Copy link
Contributor

FYI there is ongoing work on GraalVM side to make it work, I will try to share up to date news about current status.

mrFlick72 added a commit to mrFlick72/budget-service that referenced this issue Sep 20, 2022
mrFlick72 added a commit to mrFlick72/budget-service that referenced this issue Sep 20, 2022
@mhalbritter mhalbritter added theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement and removed type: enhancement A general enhancement labels Oct 17, 2022
@mhalbritter
Copy link
Contributor

There's more than just GraalVM supporting this. Currently, using @MockBean wreaks havoc even when not using native-image, just enabling AOT mode is enough.

@mhalbritter
Copy link
Contributor

We have a smoke test which uses @MockBean here: https://github.com/spring-projects/spring-aot-smoke-tests/tree/main/boot/boot-tcf

@mhalbritter
Copy link
Contributor

I've added metadata for Mockito 4.8.1 to the reachability-metadata repository. However I found no way to get the class mocks from Mockito working, as they all rely on creating classes at runtime. But it works when using the ProxyMockMaker, which is able to mock interfaces.

@eiswind
Copy link

eiswind commented Dec 7, 2022

@mhalbritter are there plans to support @MockBean? Having this with the proxymockmaker would be already a big gain.

@mhalbritter mhalbritter modified the milestones: 3.x, 3.1.x Dec 8, 2022
@mhalbritter
Copy link
Contributor

Indeed, that would be really great. Hopefully we get this working with Boot 3.1.

@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 4, 2023

Various users (example here) seems confused about seeing their unit tests broken when using just the AOT plugin, without using GraalVM native images support.

My proposal would either to:

  • Update the title of this issue in order to focus on the fact that Mockito support is broken at AOT level as mentioned by @mhalbritter here and @wilkinsona here.
  • Create a different issue focused on the broken AOT support for @MockBean and @SpyBean.

Since I am not sure we should do something specific for Mockito on native side (should be handled on GraalVM side), I would maybe favor turning this issue into fixing the AOT support, and see later if a dedicated native issue is needed, but of course up to the Boot team to decide.

@wilkinsona wilkinsona changed the title Support Mockito in native tests Support Mockito in AOT-processed tests Dec 4, 2023
@wilkinsona
Copy link
Member

Thanks, @sdeleuze. I've updated the issue's title to focus on the AOT side of things. Once that has been addressed we can consider what's left for general native support of Mockito.

@wilkinsona wilkinsona changed the title Support Mockito in AOT-processed tests Support Mockito with @MockBean and @SpyBean in AOT-processed tests Dec 4, 2023
@eiswind
Copy link

eiswind commented Dec 4, 2023

If just found with updating to 3.2 that @DisabledInAotMode did break my native tests. I had to use @DisabledInNativeTest and ignore the aot errors to make the native tests work again. There was an issue with some AotDetector beeing initialized at compile time when trying to run the native tests if I remember correctly. Should that be a seperate issue?

@wilkinsona
Copy link
Member

@eiswind That's a known issue in Spring Framework: spring-projects/spring-framework#31705

@eiswind
Copy link

eiswind commented Dec 4, 2023

@wilkinsona As always: Thanks for pointing me there.

@wilkinsona
Copy link
Member

wilkinsona commented May 31, 2024

@bclozel another one for Framework please to consider as an enhancement (if it's not already supported) to @MockitoBean and @MockitoSpyBean.

@wilkinsona
Copy link
Member

Thanks, @sbrannen.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2024
@wilkinsona wilkinsona removed this from the 3.x milestone Jun 1, 2024
@wilkinsona wilkinsona added for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another labels Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants