OpenSRP Client
Technologies
Robolectric for unit testing
Powermockito for mocking
Jacoco for code coverage
Travis for CI
Coveralls.io for viewing coverage reports
Notes:
Sample Class used for the unit tests is
org.ei.opensrp.path.activity.ChildDetailTabbedActivityUnitTest
Most tests should extend a BaseUnitTest, reusable methods can be added there
If you come across classes you cannot mock you can create a Robolectic Shadow instead
Examples are in this package.
Opensrp-client.opensrp-path.src.test.java.shared.customshadows
To use in a test simply include in the shadow class in the @Config Annotation of your Test Class at the class level. Checkout ChildDetailTabbedActivityUnitTest.java
Travis CI is configured to execute the tests on each commit, the feedback can be quickly viewed on slack’s opensrp-client channel as to whether the tests passed(from your commit)
To check out the Travis builds just got to
https://travis-ci.org/OpenSRP/opensrp-client/builds
The code coverage reports are also pushed automatically to coveralls, you can view them by going to this link
https://coveralls.io/github/OpenSRP/opensrp-client
Coveralls Color code.
If after a commit the coverall shows Green then it increased the code coverage
If it shows Gray the code coverage was retained
If it shows Red then the coverage dropped
Theoretically we should should aim for greens with each commit, that is always increase coverage with each commit.
Overall we should target 75 to 80 code coverage for the project.
More is of course much better :)
Testing Locally
In order to execute the tests locally on your dev machine and generate a coverage report just do a
./gradlew :<module name>:jacocoTestReport
After running this a code coverage report will be generated on you workstation in the paths directory under the reports folder. That is
/opensrp-client/opensrp-path/reports/jacoco/html
Clicking on this file /opensrp-client/opensrp-path/reports/jacoco/html should open on your browser the current code coverage reports per class.
If you click on an individual class you will get to see the areas of the class are covered (Highlighted in Green) and not covered (Highlighted in Red). This is useful in order to figure out which methods you should be testing to increase coverage.
The gradle task task is defined in paths build.gradle file
If you want more info or debug or stacktrace incase of error just add the usual flags --info and --debug, i.e. run
./gradlew :app:jacocoTestReport --info --stacktrace
Also checkout the gotchas here
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.