How to do TDD considering the Views are not stupid and decoupled?

from the CommonsWare Community archives

At February 10, 2019, 9:26am, ivano_trocchietto asked:

I have been to a fantastic conference with Uncle God and now I believe that I should do Test Driven Development.
But in Android IMO is not trivial. I know you are not into TDD/GIT/AGILE/CLEAN but you know a lot about Android ecosystem

In short my doubts come from the fact that as far as I read, I should avoid to use Roboelectric, and I am wondering if I can in Android really make my views really dumb so that I can Junit test all the logic behind without using an Emulator.

Is at least fascinating to think how could I achieve that for instance with RecyclerView that are full of logic?
I do not see my self make JUnit test that fail and then making pass with all this onCreateView, onBind getItemCount etc
Any thought, guide, suggestion? Even in the Web cannot find a real life TDD android tutorial( a SWIFT yes)


At February 10, 2019, 1:04pm, mmurphy replied:

Ideally, your “view” portion of an MV* is just filling in widgets and forwarding on events from those same widgets. Usually, I just test that using instrumented tests in an emulator, to the extent that I worry about it at all. Instead, I focus on testing the other letters of the MV* architecture, such as models and viewmodels. Those should be able to be unit tested, outside of an emulator. Where and how you test other things, like repositories, depends a bit on their internal structure and what they’re doing.

Ah, you mean real TDD: write the test first, then write the implementation. IMHO, real TDD does not work with GUIs. It can work for the stuff that underlies those GUIs (models, viewmodels, repositories, etc.). But, that is just my opinion.