Replies: 1 comment 3 replies
-
|
Hi! Thank you for opening the discussion. I investigated it a little bit and I think I see some possibilities to solve the problem. Separate
|
Beta Was this translation helpful? Give feedback.
-
|
Hi! Thank you for opening the discussion. I investigated it a little bit and I think I see some possibilities to solve the problem. Separate
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
First of all — thank you for Mokkery. It's the only mocking library that truly works across all KMP targets including Kotlin/Native, and it fills a huge gap in the ecosystem. The compiler plugin approach is clever and the API feels natural. Really appreciate the work you've put into this.
I'd like to raise a feature request regarding the two safety flags:
The problem I'm facing:
In my KMP project I have a class like this:
When I try to
mock<AuthInteractor>(), Mokkery refuses to fill the constructor arguments without enabling the flags above. I fully understand why these flags exist — calling constructors or inheriting classes can trigger real side effects (network calls, DB connections, thread leaks). The safety rationale is clear and correct.However, this creates a dilemma:
The feature request:
Would it be possible to introduce a way to mock a concrete or final class purely at the method-interception level — without calling its constructor at all? The idea is similar to how MockK handles this on JVM via ByteBuddy: it intercepts method calls without instantiating the real object.
I understand that on Kotlin/Native there is no bytecode manipulation, but since Mokkery already uses a compiler plugin, it might be possible to generate a mock class at compile time that:
@MockkableClassor a new dedicated API likemockConcrete<StickerMapper>()This would allow developers to opt into "mock without constructor" behavior per class, without enabling a global flag that affects the entire project.
Expected benefit:
Is something like this on the roadmap, or is there a fundamental limitation in the compiler plugin model that prevents this approach?
Thanks again for the amazing work on Mokkery — it's become an essential part of our KMP testing setup.
Beta Was this translation helpful? Give feedback.
All reactions