Open jmcaldera opened 6 years ago
If you set a breakpoint inside the block of observeForever
and debug, you'll see that it won't be reached. The reason is that GetMovies
is mocked but the test gives behaviour only to run
, so its method execute
does nothing when is called by MoviesViewModel
.
A solution might be spy GetMovies
, so real methods are called (except run
, which will be stubbed):
import org.mockito.Mockito.mock
import org.mockito.Mockito.spy
private val getMovies = spy(GetMovies(mock(MoviesRepository::class.java)))
Good catch!
@JavierSA have you tried that out? If so, I would appreciate a PR.
Thanks!
@JavierSA - Unfortunately, in my project, UseCases cannot be run (due to networking dependencies) so, I had to mock the UseCases. My PR presents an alternate solution.
@fowlerwill I think yours is better, so I've closed my PR.
Thanks everyone for the contribution! I will review those PRs asap. :heart:
Assertions made inside the observeForever block are always successful, even when they shouldn't.
For example in MoviesViewModelTest, if i say that the first element poster is equals to "IronMannnn", it will pass, even if the real value is "IronMan".