Files
2022-10-20 15:11:57 -07:00
..
2022-10-19 16:14:55 -07:00
2022-04-22 15:10:07 -07:00
2022-10-20 15:11:57 -07:00

rib-coroutines-test

This module is responsible for defining the coroutines test utils for the rib-coroutines module.

Installation

dependencies {
  implementation 'com.uber.rib:rib-coroutines-test:0.13.1'
}

Usage

RibCoroutinesRule is a Junit Rule to enable automatic setup and cleanup of TestCoroutineDispatchers with the RibCoroutineConfig.dispatchers global configuration by constructing in Tests.

@get:Rule var ribCoroutineRule = RibCoroutinesRule()

TestRibCoroutineScopes provides extension functions to enable overriding the coroutineScopes in Interactors and Workers.

Once enabled, ScopeProvider.testCoroutineScopeOverride and ScopeProvider.coroutineScope are the same instance with the only difference being ScopeProvider.testCoroutineScopeOverride is a convenience API which casts it as a TestCoroutineScope.

@Test
fun testCoroutineScope()  = runBlockingTest {
    val interactor = FakeInteractor<Presenter, Router<*>>()
    interactor.attach()

    //Enable TestCoroutineScopeOverride
    interactor.enableTestCoroutineScopeOverride()

    interactor.coroutineScope.launch {
        //Running in TestCoroutineScope
    }

    //Disable TestCoroutineScopeOverride
    interactor.disableTestCoroutineScopeOverride()
    //Cleanup TestCoroutineScope
    interactor.testCoroutineScopeOverride!!.cleanupTestCoroutines()
}