https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

salomonbrys

01/17/2022, 1:36 PM
Hey guys. A few weeks ago, I introduced Micro-Mock, a mocking processor & runtime for Kotlin Multiplatform that allows to mock interfaces with the same syntax & semantics than MockK or Mockito-Kotlin. Today I'm announcing that it has been renamed MocKMP and promoted to stable. Here is the announcement article: https://medium.com/kodein-koders/mockmp-a-mocking-processor-for-kotlin-multiplatform-51957c484fe5 The library itself lives here: https://github.com/Kodein-Framework/MocKMP We hope you'll find it usefull.
👍 6
🥳 5
K 14
🙌 5
p

Paul Woitaschek

01/18/2022, 5:26 AM
Technically, we should be able to generate implementations of abstract class or open class in Kotlin,
Have you evalulated if a mechanism like https://kotlinlang.org/docs/all-open-plugin.html could help here and merry it with mockmp?
s

salomonbrys

01/21/2022, 10:07 AM
Well, that would only work on classes of the current module. MocKMP allows you to mock any interface, whether from a library or your module sources.
a

AnaR

01/26/2022, 7:15 PM
@salomonbrys Is there a sample project I can use to figure out how to use it. I tried it with Kotlin 1.6.0 and the setup with the plugin, but, it doesn't seem to be generating the mocks.
Answering my own question: I needed to run testDebugUnitTest to generate the class. Then added the generated srcdir to commonTest.
👍 1
Ran into another problem though with trying to run the test on iOS: : Could not determine the dependencies of task 'sharedcompileTestKotlinIosX64'.
Task with path 'kspTestKotlinAndroid' not found in project ':shared'.
s

salomonbrys

01/26/2022, 10:25 PM
@anar can you provide a reproducer ?
a

AnaR

01/26/2022, 11:53 PM
Should I open an issue and add it on the project?
Issue opened. Thanks for responding.
s

salomonbrys

01/27/2022, 9:54 AM
I'll have a look asap 🙂
👍 1
a

Ahmet Özcan

02/04/2022, 2:00 PM
Hello,
How can i test interfaces with suspend functions ?
s

salomonbrys

02/04/2022, 2:02 PM
Hi @Ahmet Özcan, Mocking interfaces with suspend functions should be supported. If you find a use-case where it is not the case, please open an issue with a reproducer.
a

Ahmet Özcan

02/04/2022, 2:04 PM
this code block not get compiled
Copy code
mocker.every{
    remoteDataSource.checkUserName(isAny())
} returns DataState.Success(CheckUserNameResponse(true))
because checkUserName is a suspend function
im missing something for sure but what 😄
when i call as below its ok. But the runBlocking method is coming from my framework with exptect/actual mech.
Copy code
mocker.every{
    runBlocking {
        remoteDataSource.checkUserName(isAny())
    }
} returns DataState.Success(CheckUserNameResponse(true))
is there any other way to do that ?
Full code is
Copy code
runTest {
    mocker.every{
        runBlocking {
            remoteDataSource.checkUserName(isAny())
        }
    } returns DataState.Success(CheckUserNameResponse(true))
    state.test {
        SUT.sendIntent(RegisterWithPhoneViewStore.Intent.SetPhoneNumber(validPhoneNumber))
        var item = expectMostRecentItem()
        assertEquals(item.phoneNumber, validPhoneNumber)
        SUT.sendIntent(RegisterWithPhoneViewStore.Intent.ValidatePhoneNumber)
        item = awaitItem()
        assertTrue(item.inProgress)
        item = awaitItem()
        assertTrue(!item.inProgress)
    }

    navigation.test {
        SUT.sendIntent(RegisterWithPhoneViewStore.Intent.ValidatePhoneNumber)
        val item = awaitItem()
        println(item)
        assertTrue(item is Destination.LoginScreen)
    }

    assertTrue(onboardingManager.phoneNumber.isEmpty())
    assertEquals(OnboardingType.Empty, onboardingManager.onboardingType)
}
s

salomonbrys

02/04/2022, 2:27 PM
Investigating...
a

Ahmet Özcan

02/04/2022, 2:27 PM
🙏
s

salomonbrys

02/08/2022, 2:59 PM
@Ahmet Özcan Version
1.2.0
properly supports suspend functions. The documentation has been updated to reflect that : https://github.com/Kodein-Framework/MocKMP#defining-suspending-behaviour
a

Ahmet Özcan

02/08/2022, 3:33 PM
Thank you very much Salomon. I ll be more then happy to use this great library K
👍 1
34 Views