Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

MainViewModelTest .whenMainClicked_updateTaps has UncompletedCoroutinesError #176

Open
@dgoldhirsch

Description

@dgoldhirsch

The recommended first test case won't work any more:

@test
fun whenMainClicked_updatesTaps() {
subject.onMainViewClicked()
Truth.assertThat(subject.taps.getValueForTest()).isEqualTo("0 taps")
coroutineScope.advanceTimeBy(1000)
Truth.assertThat(subject.taps.getValueForTest()).isEqualTo("1 taps")
}

Running it as recommended, without any testing context will produce this:

Screen Shot 2022-08-26 at 12 12 20 PM

Same bug exists in the finished_code module of the codelab project.

I fixed it by upgrading in coroutines-codelab build.gradle the coroutines_android_version to '1.6.3' and using the new runTest scope:

Screen Shot 2022-08-26 at 12 15 45 PM

Also perhaps note that advanceTimeBy is deprecated since 1.6. Per the deprecation message, the recommended replacement is to advance the scheduler and runCurrent, manually, e.g.:

Screen Shot 2022-08-26 at 12 30 58 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions