Getting started
-
Apply the Gradle plugin and activate the helper dependency:
plugins { kotlin("multiplatform") id("org.kodein.mock.mockmp") version "1.17.0" } kotlin { // Your Koltin/Multiplatform configuration } mockmp { usesHelper = true installWorkaround() } -
Create a test class that declares injected mocks and fakes:
class MyTest : TestsWithMocks() { override fun setUpMocks() = injectMocks(mocker) (1) @Mock lateinit var view: View @Fake lateinit var model: Model val controller by withMocks { Controller(view = view, firstModel = model) } @Test fun controllerTest() { every { view.render(isAny()) } returns true controller.start() verify { view.render(model) } } }1 This is mandatory and cannot be generated. You need to run the KSP generation at least once for your IDE to see the injectMocksgenerated function.Every property annotated by @Mock, annotated by@Fakeor delegated towithMockswill be reset fresh between each test.