salomonbrys
11/15/2021, 11:22 AMclass MyTest {
@set:Mock lateinit var view: View
@set:Fake lateinit var model: Model
lateinit var controller: Controller
val mocker = Mocker()
@BeforeTest fun setUp() {
mocker.reset()
injectMocks(mocker)
controller = Controller(view = view, firstModel = model)
}
@Test fun controllerTest() {
mocker.on { view.render(isAny()) } returns true
controller.start()
mocker.verify { view.render(model) }
}
}
The following limitations apply:
• Mocking only applies to interfaces
• Faking only applies to concrete trees
The processor generates:
• Mocks of interfaces, allowing to mock behaviour & verify calls.
• Fakes of data classes, filling them of nulls, zeros, empty strings, and alike.
• Injector for test classes.
You’ll find it here : https://github.com/Kodein-Framework/Micro-Mock
We are using this in some of our own Multiplatform tests.
I hope it will be useful to the community 😉Big Chungus
11/15/2021, 11:30 AM