micronaut-projects / micronaut-test

Repository for Test Related Utilities for Micronaut
Apache License 2.0
80 stars 60 forks source link

DB shouldn't be required when using `@MockBean` for repositories #1032

Open Nahuel92 opened 1 month ago

Nahuel92 commented 1 month ago

Issue description

Hi there!

This is an improvement request/discussion-opener on something I bumped into recently in other issues:

Please feel free to close it if it's innappropriate.

Now, down to business. I consider that the current @MockBean behavior on repositories is not quite right since, as of now, if a repository is mocked with this annotation, a DB is still required for the interceptor chain to create a TX manager (for more info, please read this comment and the previous issues I linked before).

To me, this defeats the purpose of @MockBean as it forces us to still use a real thing (granted, in the end I achieved my goal using H2, but it feels more of a workaround than a proper solution). If a repository is mocked, why the framework still requires a DB when the idea is to not have one in the first place? I may be wrong on my thought, so I'm open to any feedback/suggestion.

Thanks.

P.S.: And thanks for your effort and dedication, I really like Micronaut.

graemerocher commented 1 month ago

I think we would need to do something in the transaction interceptor. WDYT @dstepanov ?

dstepanov commented 1 month ago

I think we should support replacing the target with the interceptor somehow