codelab-kotlin-coroutines icon indicating copy to clipboard operation
codelab-kotlin-coroutines copied to clipboard

Test failing for MainViewModelTest.kt

Open svvashishtha opened this issue 5 years ago • 0 comments
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

svvashishtha avatar Mar 07 '20 09:03 svvashishtha