17

Is there a way to run unit tests for Android from Eclipse in a way that will instrument the code and measure test code coverage?

I'm looking for a simple way to find out which parts of my application aren't tested yet, fix the test cases and see if that helped.

4 Answers 4

8

Disclaimer: I'm an Atlassian

The Atlassian Clover tool has also support for Android - it measures coverage for both application code and unit tests. Although in alpha stage, it works quite well - it works with Eclipse version 3.6.2 and higher.

If you want to find areas of your application which require improvement, then the following Clover features will be perfect for this task:

  • Clover Dashboard
  • Coverage Cloud Report
  • Coverage TreeMap Report
  • Coverage Explorer

Oh, and the Clover HTML Report looks fantastic!

Check this: https://confluence.atlassian.com/display/CLOVER/Clover-for-Android

Sign up to request clarification or add additional context in comments.

Comments

3

I've been used EMMA (android already support it) for code coverage (and android-junit-report for test reports), here is a summary:

  • Create android project (or library)

android.bat update project -p project -n my_project -t android-16

cd project

ant emma clean debug

  • create a test project (linked to previous library)

android.bat update project --library ..\project -p project_Test -n project_Test -t

  • in case the main project is not a library

android.bat update project -m ..\project -p project_Test -n project_Test -t

ant emma clean debug install I ddidn't use 'test' since I want to run my own instrument

adb shell am instrument -e coverage true -e coverageFile sdcard/coverage.ec -w com..myproject.test/com.zutubi.android.junitreport.JUnitReportTestRunner

  • Pull files from device (emulator)

adb pull sdcard/junit-report.xml

adb pull sdcard/coverage.ec

  • Generate XML report (can also generate html report)

java -cp emma.jar emma report -r xml -in bin/coverage.em,coverage.ec

  • Generate HTML report (can also generate html report)

java -cp emma.jar emma report -r html -in bin/coverage.em,coverage.ec

  • Using Post-builds (Jenkins):

    • JUnit report XML
    • Emma Coverage report (give the coverage.xml as input)

Don't need the emma.jar into libs

Check it out from my blog

Comments

2

Install EclEmma from Eclipse Marketplace.

If you have <path to test project>/build.xml file rename it.

I was able to generate test coverage report by executing following from the console:

<path to android tools>android update test-project -m <path to app project> -p <path to test project> + Enter,

cd <path to test project> + Enter,

ant emma debug install test + Enter,

where <path to android tools> is /opt/android-sdk-linux/tools/ on my machine - the folder where android SDK is installed.

This generated <path to test project>/bin/coverage.html file.

If you get "wrong JAVA_HOME" error execute gksu gedit /etc/environment + Enter, correct JAVA_HOME, save the file, log out or reboot and try again.

Source: http://blog.rabidgremlin.com/2010/11/19/android-tips-generating-a-coverage-report-for-your-unit-tests/

Comments

2

Take a look at this article: http://blog.pboos.ch/2011/06/coverage-fo-android-tests/

EDIT: Updated link: https://github.com/pboos/blog.pboos.ch/blob/master/_posts/2011-06-29-coverage-fo-android-tests.markdown

2 Comments

While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
This link is now broken.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.