4 ms·
Meh. MVVM just moves the problem, so what if your view controllers are testable but now your ViewModel isn't. You need to be testing those 400 lines of code. S
by fleitz 11y ago
Meh. MVVM just moves the problem, so what if your view controllers are testable but now your ViewModel isn't. You need to be testing those 400 lines of code.
Since it's UI code that usually breaks when exposed to weird patterns just write something that sends random touches to the screen in a rapid manner, it surfaces the bugs really quickly and generally disallows bandaid patches.
I find regular UI unit tests on the verge of useless, it's generally just coding the pattern the developer moves through the UI anyway, eg. fill first form, second, press submit, not random stuff in 3rd form, press submit while simultaneously pressing the back button, then move forward back into the same controller.
eg. If you press a text field and the back button at the same time does it leave the keyboard up when navigating back? That's where the real bugs are.
The solution is extensions and inheritance that cut down on boiler plate in the VC, as well as child view controllers.
Chuck your models into your views and call it a day. For example take your ViewCell, add a method called setData: / setModel: / configureCell: whatever you want to call it, and put your UI manipulation code in there. The puritans will tell you you're doing it wrong but it declutters the code into a bunch of 25-100 line views.
If you really need a lot of logic in there make a ViewController for that view and add it as a childViewController.