I found some strange condition when creating a test for a code with RxJava.
"Verify movie not empty and error" {
Mockito.`when`(networkSource.getMovies())
.then { mock<Single<List<Movie>>>() }
tested.getMovies().test().also {
it.assertNoErrors()
it.assertComplete()
it.assertValueCount(1)
}
}
The test is simply asserting my Single
is running completely without error and exactly return one value.
The problem is, my Single
is neither completed or having an error. It also not returning any value.
java.lang.AssertionError: Not completed (latch = 1, values = 0, errors = 0, completions = 0)
After scratching my head for the rest of the day, it turns out my test code that was wrong. I stub one of my Single
to return a mocked Single
that doesn’t have behavior like the real Single
at all.
So lesson learnt here:
You can find the full sample on my Github
Until next time. Cao ~ 👋