MocKMP icon indicating copy to clipboard operation
MocKMP copied to clipboard

Feature Request: Enable mocking for `expect interface`

Open ankushg opened this issue 3 years ago • 4 comments

It would be nice to be able to mock an expect interface with generated mocks for the actual interface for each target 😄

ankushg avatar May 09 '22 23:05 ankushg

MocKMP is a test tool. Having a tool that generates actual implementations for expect interfaces is not a test tool and outside the scope of MocKMP.

SalomonBrys avatar May 12 '22 10:05 SalomonBrys

Sorry I wasn’t clear: I’m definitely trying to use it in tests!

To be more specific:

  • I’ve got an expect interface in commonMain,
  • already have actual interfaces in JVM and iOS
  • My commonMain code extensively uses the expect interface

What I’m looking for is being able to

  • write a test case in commonTest that only verifies behavior of methods on the common expect interface
  • tell mockmp to mock the expect interface in commonTest, and
  • have mockmp generate mocks via the (already existing!) actual interfaces for each target
  • Have mockmp allow me to mock the common methods in commonTest

ankushg avatar May 12 '22 13:05 ankushg

That is not possible at the moment, due to this KSP issue: https://github.com/google/ksp/issues/567. This forces us to apply a workaround: generate code for jvm (with the kspJvmTest configuration) and apply the result to all source sets. This evidently breaks expect interfaces. Once this KSP issue is fixed, then we'll be able to work on expect interfaces: we'll have KSP will run on each source-set, generating a mock for each full actual interface.

SalomonBrys avatar May 12 '22 17:05 SalomonBrys

I reopen this issue because the use-case is valid, and MocKMP does not support it at the moment. However, until the aforementioned KSP issue is fixed, consider it dormant, as I don't think it can be done.

SalomonBrys avatar May 12 '22 17:05 SalomonBrys