Skip to content

controller testing

Florian Schuster edited this page Apr 29, 2022 · 17 revisions

state

to test a Controller use Controller.state:

private val testScope = TestScope(UnconfinedTestDispatcher())

@Test
fun testController() {
    // given
    val sut = // create Controller from testScope

    // when
    sut.action(Action.SetCounter(3))
    testScope.advanceTimeBy(5000)

    // then
    assertEquals(3, sut.state.value.counterValue)
}

when not using a Flow testing framework, one can also use val states: List<State> = controller.state.toList() to verify states

delay controls

val testScope = TestScope()
val sut = testScope.createController<Action, Mutation, State>(
    initialState = State(value = 0),
    ...
)
testScope.advanceTimeBy(delayTimeMillis = 5000)

examples

Clone this wiki locally