-
Notifications
You must be signed in to change notification settings - Fork 9
controller testing
Florian Schuster edited this page Apr 7, 2022
·
19 revisions
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 TestFlow testing can also be done with val states: List<State> = controller.state.toList().
val testScope = TestScope()
val sut = testScope.createController<Action, Mutation, State>(
initialState = State(value = 0),
...
)
testScope.advanceTimeBy(delayTimeMillis = 5000)