androidunit-testingantcode-coverageemma

How To do code coverage with emma during Android Unit Tests


You're looking for a simple way to do Android Unit Tests with code coverage and a report? Here you get a short HowTo.


Solution

  • First of all i assume that you have already a project and a test project with test cases. Also you have installed the Android sdk. The android testing framework has already a built-in ability to generate a code coverage report about your tests. This built-in ability is based on emma.

    Firs of all you've to create a build.xml for your project, which should be tested:

    android update project --path <Path to your Project>
    

    Next step is to create the build.xml for the test project (where the test cases are located):

    android update test-project -m <Path to your Project> -p <Path to your Testproject>
    

    In the next step you ccan run the coverage. Therefor you must switch into you Testproject:

    cd <Path to your Testproject>
    ant emma debug install test
    

    This will build, instrument, deploy and run your unit tests. It will also generate a HTML coverage report. The location of the report will be displayed in the last few lines of the Ant script’s output.

    For more Details: http://developer.android.com/tools/building/building-cmdline.html#AntReference

    Troubleshooting: