You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Problem:
To unit test a function that returns an instance of ChangeState<S> we need to "unwrap" it to get to the next state value by calling changeState.reduce(currentState). Not a big deal, but some repetitive boilerplate if you have to do that all the time for all of your tests. Also ChangeState is not meant to be compared directly with via equal with a real State like Assert.assertEquals(expectedState, changeState) (expectedState is of type State and changeState of type ChangeState).
Maybe we should provide an additional artifact to provide a more convenient way to unit test functions that involve ChangeState. Could be just a simple extension function like ChangeState.test(currentState) { newState -> ... } where you can do some assertions inside the lambda block on the newState object.
Or we could go wilder and define some more convenient API like:
@Test
fun`in loading state then load items and transition to content state`() = runBlocking {
val items:List<Item> =...
givenState<LoadingState, State>(LoadingState)
.onEnter(::loadFirstPage) // loadFirstPage() is the function that we want to unit test
.then(ShowContentState(notifications = items, currentPage =1)) // Expected state
}
👍Being able to test state transition directly without driving the state machine from the initial state all the way to the state before that state transition under testing would make tests cleaner and more focused.
The Problem:
To unit test a function that returns an instance of
ChangeState<S>
we need to "unwrap" it to get to the next state value by callingchangeState.reduce(currentState)
. Not a big deal, but some repetitive boilerplate if you have to do that all the time for all of your tests. AlsoChangeState
is not meant to be compared directly with via equal with a realState
likeAssert.assertEquals(expectedState, changeState)
(expectedState is of type State and changeState of type ChangeState).Maybe we should provide an additional artifact to provide a more convenient way to unit test functions that involve
ChangeState
. Could be just a simple extension function likeChangeState.test(currentState) { newState -> ... }
where you can do some assertions inside the lambda block on thenewState
object.Or we could go wilder and define some more convenient API like:
UnitTestDSL.kt.txt
@gabrielittner @dmo60 do you thing that would be useful?
The text was updated successfully, but these errors were encountered: