Gautam Shorewala
09/30/2025, 1:03 PMclass TestDispatcherTest : FunSpec() {
init {
coroutineTestScope = true
test("this test uses a test dispatcher") {
}
test("and so does this test!") {
}
}
}
now when i tried this in my code there the test crashes with
Dispatchers.Main was accessed when the platform dispatcher was absent and the test dispatcher was unset. Please make sure that Dispatchers.setMain() is called before accessing Dispatchers.Main and that Dispatchers.Main is not accessed after Dispatchers.resetMain().
This is a snippet of my test
class EnterOtpComponentTest : FunSpec() {
private lateinit var component: EnterOtpComponent
private val mockOtpRepository = mockk<OtpRepository>(relaxed = true)
private val testNumber = "1234567890"
override val extensions: List<Extension> = listOf(
KoinExtension(
module = module {
single<OtpRepository> { mockOtpRepository }
},
)
)
init {
coroutineTestScope = true
mockkObject(Analytics)
beforeTest {
clearAllMocks()
}
testSendOtp()
testOnOtpEnter()
}
is there anything i might have missed or doing wrong?solonovamax
10/05/2025, 11:53 PMsolonovamax
10/05/2025, 11:54 PM