Its ideal to maintain a benchmark for coverage within the code base. Coverage is measured by classes, functions and line covered. We should aim for > 80% coverage.
We currently use MVP as the design pattern which makes its easy to test and also better structured code overall.
Testing Tools available for Android
JUnit (main testing framework in Java ecosystem)
Mockito (used to mock objects)
Powermock (extension of mockito, adds mocking static variables and functions )
Roboelectric (provides android runtime on jvm for unit testing android dependancies)
AndroidJUnit and Espresso (instrumented tests)
Testing Tools available for OpenSRP server
(1-3 ) above on the android section
SpringJUnit4ClassRunner (Used to bootsrap spring IOC container for testing )
Important points to remember
Its important to consider the purpose and stengths of each tool for testing. Consider the tool on frameword from above list starting from the top.
Dont mix powermock with Roboelectric or AndroidJUnit/Espresso. Tests will not work since powemock affects classloading
Dont Prepare a class for Test using the powermock if the same class is under test. Jacoco will not be able to report coverage for such tests
Write tests when writing the code
If (4) is not possible the write the code keeping in mind that it needs to be tested
Mockito can be used will the other testing tools
Avoid static methods if they need to have state or call instances of other classes which track state
Dont instanc
MVP design Pattern
Model (includes Interacators) Use JUnit and Mockito
Presenter
If the presenter have any android dependencies then use Robolectric +Mockito
If the presenter does not have any android dependencies use JUnit and Mockito
Views Use Robolectric +Mockito
Utils and Helpers (JUnit +Mockito)