In which task and step of the codelab can this issue be found?
Task 10 - Step 10 - To apply this rule to your tests, add the @get:Rule annotation to the testDispatcher property.
Describe the problem
After add TestDispatcherRule, it's expected to pass unit test, but it fails because of excpected value. In step 5, expected value is given like this:
@Test
fun marsViewModel_getMarsPhotos_verifyMarsUiStateSuccess() =
runTest {
val marsViewModel = MarsViewModel(
marsPhotosRepository = FakeNetworkMarsPhotosRepository()
)
assertEquals(
MarsUiState.Success("Success: ${FakeDataSource.photosList.size} Mars " +
"photos retrieved"),
marsViewModel.marsUiState
)
}
However, actual value is MarsUiState.Success("Success. ${listResult.size} Mars photos retrieved") in MarsViewModel. So expected value should be with "." instead of ":" in step 5.
Or vice versa, it can be fixed with MarsUiState.Success("Success: ${listResult.size} Mars photos retrieved") in MarsViewModel in repo-starter branch .
Steps to reproduce?
Go to... from step 5 to step 10
Click on... after add TestDispatcherRule , run unit test
See error...
expected:<Success(photos=Success: 2 Mars photos retrieved)> but was:<Success(photos=Success. 2 Mars photos retrieved)>
Expected :Success(photos=Success: 2 Mars photos retrieved)
Actual :Success(photos=Success. 2 Mars photos retrieved)
<Click to see difference>
java.lang.AssertionError: expected:<Success(photos=Success: 2 Mars photos retrieved)> but was:<Success(photos=Success. 2 Mars photos retrieved)>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at com.example.marsphotos.ui.screens.MarsViewModelTest$marsViewModel_getMarsPhotos_verifyMarsUiStateSuccess$1.invokeSuspend(MarsViewModelTest.kt:22)
VersionsAndroid Studio version:API version of the emulator:
Additional informationInclude screenshots if they would be useful in clarifying the problem.
URL of codelab: https://developer.android.com/codelabs/basic-android-kotlin-compose-add-repository?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-5-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-add-repository#9
In which task and step of the codelab can this issue be found? Task 10 - Step 10 - To apply this rule to your tests, add the @get:Rule annotation to the testDispatcher property.
Describe the problem After add TestDispatcherRule, it's expected to pass unit test, but it fails because of excpected value. In step 5, expected value is given like this:
However, actual value is MarsUiState.Success("Success. ${listResult.size} Mars photos retrieved") in MarsViewModel. So expected value should be with "." instead of ":" in step 5.
Or vice versa, it can be fixed with MarsUiState.Success("Success: ${listResult.size} Mars photos retrieved") in MarsViewModel in repo-starter branch .
Steps to reproduce?
Versions Android Studio version: API version of the emulator:
Additional information Include screenshots if they would be useful in clarifying the problem.