Pages

Saturday, February 20, 2016

Android Code Coverage Unit Testing

This is a very small post for all those who have been strugling to generate the Android Test Coverage Using the ant scripts give by android sdk itself.


I am assuming that you have created one project containing the actual source code to be tested - assume it is called "MyProject" and you have created another test project that tests MyProject, that is named MyProjectTest.


Then, you have written jUnit tests using the inherent testing support framework with android. Now, you have run your unit tests and they run successfully in ecplise. You then, what to check on the code coverage of these unit tests. Here are the steps for the same:



  •    At the command prompt, change directory to the MyProject folder
  •    Rename the existing build.xml to build_orig.xml
  •    Run this command:
android update project -p . (including the last dot)
  •    Then change directory to cd ..MyProjectTest
  •    Rename the existing build.xml to build_orig.xml
  •    Run this command:
android update test-project -m D:/..../source/MyProject -p .  (including the last dot and where you give your complete path to the MyProject folder after -m)
  •    Then, run the  command -
ant emma debug install test
This should generate a html report of the coverage under MyProjectTest/coverage


Troubleshooting:

  •    Incase you get an error "remote object coverage.ec does not exist" then start adb shell in another command prompt - in order to give write permissions to the sdcard for writing the coverage.ec file
  •    Then, run the following command at the shell
mount -o remount rw /sdcard
  •    Then you should be able to generate the report.


Related Posts by Categories

0 comments:

Post a Comment