Hello, I’m using mocKMP, want to say ty for nice plugin.
I have a question, is it possible to override mock return value in the concrete unit test?
r
romainbsl
02/27/2024, 2:53 PM
You mean something like this?
Copy code
mocker.every { db.loadUser("123") } returns null // first call
mocker.every { db.loadUser("456") } returns FakeUser() // second call
romainbsl
02/27/2024, 2:54 PM
Or like this?
Copy code
mocker.every { db.loadUser("123") } returns null // first call
// Do something that triggers the first call
mocker.every { db.loadUser("123") } returns FakeUser() // second call
d
Dmitry Danilau
02/27/2024, 3:22 PM
something like
Copy code
@BeforeTest
fun setup() { // should use library setup func.
mocker.every { db.loadUser("123") } returns null // to bypass all test that in flow using that mock
}
@Test
fun test() {
mocker.every { db.loadUser("123") } returns FakeUser() // specifically check how flow behaves with the return value
// test logic
}
r
romainbsl
02/27/2024, 9:25 PM
You can do this using a variable
Copy code
// Declare reusable mock
val everyUserLoad by lazy { mocker.every { db.loadUser("123") } }
@BeforeTest
fun setup() { // should use library setup func.
everyUserLoad returns null // to bypass all test that in flow using that mock
}
@Test
fun test() {
everyUserLoad returns FakeUser() // specifically check how flow behaves with the return value
// test logic
}