Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact for Testing #137

Open
sockeqwe opened this issue Jun 19, 2021 · 1 comment
Open

Artifact for Testing #137

sockeqwe opened this issue Jun 19, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@sockeqwe
Copy link
Collaborator

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

    }

UnitTestDSL.kt.txt

@gabrielittner @dmo60 do you thing that would be useful?

@sockeqwe sockeqwe added the enhancement New feature or request label Jun 19, 2021
@sockeqwe sockeqwe added this to the 1.0 milestone Sep 19, 2021
@ychescale9
Copy link
Contributor

👍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.

@sockeqwe sockeqwe removed this from the 1.0 milestone Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants