https://kotlinlang.org logo
#android
Title
# android
l

Lou Morda

03/13/2019, 3:30 PM
Hello everybody does anyone have sample code or github project showing how to write unit tests in Android for the new-ish stable Kotlin coroutines 1.x.x? I had a project using MVVM and Kotlin experimental coroutines. My unit tests are failing now that I upgraded. I added this: testImplementation "org.jetbrains.kotlinxkotlinx coroutines test$rootProject.coroutineVersion" and have resolved one of the issues but now I'm getting a getMainLooper is not mocked error. Was hoping someone could help me out, thanks!
g

ghedeon

03/13/2019, 3:49 PM
Copy code
@Before
    fun setup() {
        Dispatchers.setMain(Dispatchers.Unconfined)
    }

    @After
    fun tearDown() {
        Dispatchers.resetMain()
    }
I have to admit that discoverability of this solution is pretty low.
l

Lou Morda

03/13/2019, 8:26 PM
Thanks for your help! I think that fixed one of my blockers but I'm still stuck on what I think is my last problem.