codelab-kotlin-coroutines
codelab-kotlin-coroutines copied to clipboard
Test failing for MainViewModelTest.kt
trafficstars
While running the first test for MainViewModelTest.kt my test failed every time until I modified the code from codelab myself. code provided in codelab
@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")
}
Code after I modified it
@Test
fun whenMainClicked_updatesTaps() {
Truth.assertThat(subject.taps.getValueForTest()).isEqualTo("0 taps")
subject.onMainViewClicked()
coroutineScope.advanceTimeBy(1000)
Truth.assertThat(subject.taps.getValueForTest()).isEqualTo("1 taps")
}
when the test failed, I always get this result
expected: 0 taps
but was : 1 taps
Expected :0 taps
Actual :1 taps