testOnUIThread

fun testOnUIThread(configuration: Configuration, cancelScopeAfterTest: Boolean = false, block: suspend Context.() -> Unit)

Run your test block on the UI thread and inside the TestContext.

Optionally with cancelScopeAfterTest you can run your test block inside a separately launched job, which is canceled after your block is run. The scope waits till this is completed by joining.

This can be handy for testing classes that rely on scopes that eventually get canceled, e.g. because they are canceled automatically by a lifecycle event.

Parameters

configuration

The Configuration to configure the TestContext.

block

test block to be run on the UI thread and in the test context.

cancelScopeAfterTest

whether to cancel the coroutinescope your block ran in after it's done.