Skip to content

net.natura.testcommons.rules.CoroutinesRule

Lucas de Souza da Conceição edited this page Jul 10, 2020 · 1 revision

CoroutinesRule

class CoroutinesRule : TestRule

A JUnit4 test rule to allow testing coroutines that use the main dispatcher. Without this you'd run into "java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used"

Example usage:

class MyTest {

    @ExperimentalCoroutinesApi
    @get:Rule
    val coroutinesRule = CoroutinesRule()
}

See also https://gist.github.com/AniketSK/0fd48da9ed969eee307f92457115612a

Clone this wiki locally