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
Description
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:
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:
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.:
Metadata
Metadata
Assignees
Labels
No labels