Can someone help me understand unit testing? Feels like I'm changing my code just to pass the test.

in the first codeblock, you have a reference to the regexmatcher from an android pattern. in pure mvp, you would abstract that in some way (I personally just have view implement it, you could also move it into its own class)

the whole idea is that you remove platform-specific code from your presenter and test the interactions with the view. if your app communicates to a webserver and relies on the webserver to implement the business logic, then that's it for app-side testing.

if your app handles business logic, then you'd write tests for that aswell and because you abstracted every bit of android-specific code away, you can run your tests in the jvm instead of having to use slower, more expensive device tests

the annoying thing is, like you mentioned already, that you have to include mocked objects for every dependency in your presenter. I personally couldn't get mockito to work (there was an issue with some other dependencies in my code), so I wrote classes that implement my interfaces (returning null for everything) and overriding the methods in my tests (here's a gist of what I mean by that: link

/r/androiddev Thread Parent