kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
183 stars 12 forks source link

Android tests failing after updating from 1.13.0 to 1.15.0 #63

Closed kaszabimre closed 7 months ago

kaszabimre commented 1 year ago

Hello,

I recently upgraded from version 1.13.0 to 1.15.0 in the MocKMP repository. Post-upgrade, I've encountered issues with my Android tests. They're now failing with the following error:


java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked.

It's worth noting that this issue was not present in version 1.13.0.

You can see the issue here: https://github.com/apter-tech/GitHubUserFinderKMM/actions/runs/5783004559/job/15670935213#step:7:108

Could anyone provide insights on what might have changed between these versions to cause this error? Any assistance would be greatly appreciated.

Thank you.

kaszabimre commented 1 year ago

Upon closer inspection, I discovered that the swift solution lies in the proper placement of the Dispatchers.setMain(Dispatchers.Unconfined) call. It should be invoked before the injectMocks(mocker) call, specifically within the override fun setUpMocks() function. When attempted within the initMocksBeforeTest() function, the solution doesn't take effect, as it becomes essential for the initDeferred() call to consider whether the setMain has been configured or not.

Here's the corrected sequence for reference:

Screenshot 2023-08-09 at 14 22 34