<@U0PQ0GVLM> `runBlocking` and `join` all jobs wit...
# coroutines
d
@marcinmoskala
runBlocking
and
join
all jobs with
delay
after, have
refreshList
as mocked interface, and check if being called expected x times for delay?
m
Such unit test will take a lot of time will not be trustable - there always can be few more or less tick of clock and that will result with differences in number of calls.
d
@marcinmoskala That's the problem when testing views in general... usually when practicing MVP, the view is supposed to be 'dumb' and do VERY simple things that the presenter tells it to do... these things are so simple they don't need tests... so basically it would be enough to test that the presenter calls
startPeriodicRefresh()
at the right time and count on the view to carry it out properly... But if one needs to make these tests.. I guess they'll have to be painful and unexact...
The
AUTO_REFRESH_TIME_MS
could be a param though -- which is sometimes more the presenter turf, since sometimes a user might want to set how often or if it should be refreshed...
m
@dave08 This is part of my Presenter and my view is as dumb as it can be. But thunk you for the idea because this lead me to a way to test it - I extracted this periodic call functionality as a mockable use-case and in Presenter I test if it is correctly called. Separate tests will be for this use case. https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/android/app/src/test/java/com/marcinmoskala/kotlinacademy/NewsPresenterUnitTest.kt https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/common-client/src/main/kotlin/com/marcinmoskala/kotlinacademy/presentation/news/NewsPresenter.kt https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/common-client/src/main/kotlin/com/marcinmoskala/kotlinacademy/usecases/PeriodicCaller.kt
d
@marcinmoskala I really like your coding style! I guess I'll have what to learn from too 😄.
m
@dave08 Thank you 🙂 But this tests are far from being readable 😕 It is not easy to make good tests without support libraries, and I am not using it because I would like this tests to be placed in common-platform module which is common module