You want to have a nice report how much you cover with your Android unit tests? Here a quick walkthrough how to get such a report (see screenshots of report below).
In this example I expect that your test project is in a folder "tests" in your project folder which gets tested.
- Create a build.xml for your project (if it does not yet exist)
cd <main project folder> android update project --path .
- Create the build.xml for the test project (that will allow us to do the coverage)
android update test-project -m <full path to main project> -p tests/
Somehow "." does not work and you have to use the full path like “/home/pboos/develop/workspace/project”
- Run coverage
cd tests/ ant coverage
This will print out the path to the html file where you can see a nice report. Should be in "tests/coverage/coverage.html".
If you have libraries that you use and you get an error. Make sure you put them into a “libs” directory. ant automatically adds the libraries in “libs” to the build path.
Example for coverage report:
If you get an error, that emma.jar (or android) is not in your classpath, you might have forgotten to add the tools directory to your classpath. Follow the instructions below "How to update your PATH" on http://developer.android.com/sdk/installing.html#sdkContents. As well make sure that you have updated the Android SDK Tools (I used revision 11, when I wrote this). How to do this is here: http://developer.android.com/sdk/adding-components.html