Harlo, how can we mock in the iosTest under the sh...
# multiplatform
l
Harlo, how can we mock in the iosTest under the shared business logic? We use mockk but it seems that iosTest cannot have dependency to the mockk.
s
Try to not use mocking libraries/frameworks in your common code. Instead, let your tests implement the interfaces on the edges/dependencies of your code-under-test. In my opinion, mocking should only be used if you just can't provide these types of edges/implementations (eg Android service/manager classes) or when you must verify behavior/side-effects. Since KMP is common code, it shouldn't rely on Android/iOS/etc specific services, and interactions with Android/iOS/etc specific services should be abstracted out and injected. Your tests can then inject dummy/fake interface implementations.
h
I use the MocKMP library for mocking. This library can only mock interfaces, and there are issues with mocking expect/actual interfaces (and since im using them, i cannot actually run the iosTest at the moment). Anyway i like this library for mocking quite a lot. Yes you must have your classes you want to mock be defined by an interface, which I wasnt used to in the Android mocking libraries, but once I set up the project to always define interfaces for classes i might wanna mock, it works really nice. You can easily mock method calls, and you have an easy way to exhaustively verify all mocks that you expect are called in order.