...
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
Don't instantiate objects in a method that would be need to when testing that function works(tight coupling)
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)
Interpreting the coveralls report
The below is a report for the coveralls that is on the PR after coveralls runs sucessfully. The report is usually edited after new commits
From the above
Info |
---|
19 of 520 (80.58%) changed or added relevant lines in 17 files are covered. |
( This show % percentage of new code that has been tested) This should be used to benchmark if the PR has meet the requirement for the project
Info |
---|
Overall coverage increased (+1.6%) to 60.157% |
This shows the overall change to the test coverage
...
The above shows 3 main metrics
Covered Lines (Lines that have been tested in this PR)
Changed/Added Lines (The number of lines that was changed on the PR)
% (The % of lines that the class has been tested on this PR)
On clicking each line above one is able to know which lines have not been tested. They will he highlighted in read and tagged as new as shown below