Multiplatform Kotlin library for mocking.
1. Add plugin to gradle:
plugins {
// ...
id("com.pega.mmock") version <plugin-version>
}
// ...
kotlin {
// ...
sourceSets {
val commonMain by gettting {
dependencies {
// ...
implementation("com.pega.mmock:mmock-runtime:$mmockVersion")
}
}
}
}
2. Annotate interface
package com.example
import com.pega.mmock.GenerateMock
@GenerateMock
interface MyInteface {
fun myFunction(arg1: Int): Int
}
3. Use mocks in tests
package com.example
import com.pega.mmock.dsl.any
import com.pega.mmock.dsl.once
import com.pega.mmock.withMMock
class TestClass {
@Test
fun exampleTest() = withMMock {
val myInterface = mock.MyInterface()
every { myInterface.myFunction(any()) } returns 2
assertEquals(2, myInterface.myFunction(1))
verify {
invocation { myInterface.myFunction(any()) } called once
}
}
}
For more detailed user guide go to usage.md