Hi, I updated the Kotiln version and migrating to ...
# test
m
Hi, I updated the Kotiln version and migrating to
runTest
alternate from
runBlocking
and I'm facing an issue in testing a specific use case. Here is a simplified version of the test case I want to run.
Copy code
@Test(expected = NullPointerException::class)
    fun test() = runTest {

        //In my actual code, I'm testing a ViewModel which uses viewModelScope to launch a coroutine
        //and it will throw an exception for a specific case.
        val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
        scope.launch {
            throw NullPointerException("error")
        }
    }
Seems this issue was already discussed here https://kotlinlang.slack.com/archives/C1CFAFJSK/p1642773185273800 and the solution from there works for me too (setting
UnconfinedTestDispatcher
as
Dispatchers.setMain
)