Skip to content

net.natura.testcommons.extensions.CoroutinesExtension

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

CoroutinesExtension

class CoroutinesExtension : BeforeEachCallback, AfterEachCallback

A JUnit5 test extension 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:

@ExtendWith(CoroutinesExtension::class)
class MyTest {
}

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

Clone this wiki locally