https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

dave08

11/22/2017, 2:34 PM
@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

marcinmoskala

11/22/2017, 3:36 PM
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

dave08

11/22/2017, 4:23 PM
@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

marcinmoskala

11/23/2017, 5:54 AM
@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

dave08

11/23/2017, 12:18 PM
@marcinmoskala I really like your coding style! I guess I'll have what to learn from too 😄.
m

marcinmoskala

11/23/2017, 3:07 PM
@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
2 Views