-
Notifications
You must be signed in to change notification settings - Fork 8
controller testing
Florian Schuster edited this page Apr 29, 2022
·
17 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 Flow
testing framework, one can also use val states: List<State> = controller.state.toList()
to verify states
val testScope = TestScope()
val sut = testScope.createController<Action, Mutation, State>(
initialState = State(value = 0),
...
)
testScope.advanceTimeBy(delayTimeMillis = 5000)