Laurent Thiebaud
05/21/2024, 3:24 PMclass TheBug {
@Test
fun test(): Unit = runBlocking{
val service = mock<MyService> {
onBlocking {
with(any<MyContext>()) {
myMethod()
}
}.doReturn(true)
}
with(MyContext("toto")) {
service.myMethod() shouldBe true
}
}
}
class MyService {
context(MyContext)
suspend fun myMethod(): Boolean {
return true
}
}
data class MyContext(val string: String)
Test result is
java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()"If the method • isn't suspended, • or doesn't require a context • or returns a data class instead of a boolean then it works as expected Any idea how I could bypass it 🙏? Don't want to remove some unit tests because of it...
Oğuzhan Soykan
05/22/2024, 12:44 PMLaurent Thiebaud
05/22/2024, 12:46 PMOğuzhan Soykan
05/22/2024, 3:50 PMLaurent Thiebaud
05/27/2024, 1:07 PM