Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are my alternatives for test code coverage on Android?

I know Android's Ant tooling comes with built-in Emma code coverage, but Emma's reports look more and more dated and cannot be easily integrated into other coverage reports or even Sonar, basically because Emma lacks a detailed XML reporting format. What I want to achieve is

  • code coverage for unit tests (Robolectric-based, already done with Cobertura)
  • code coverage for integration tests (Robotium-/emulator-based, currently done separately with Emma)
  • ideally merging code coverage results (this is IMHO only possible with Cobertura and requires the raw *.ser files from every test execution)
  • publishing to Sonar (currently only done with the unit test coverage, Sonar understands only one coverage format to my knowledge)

Do I have any alternatives?

edit: This post on sonar-devel probably sums up the current state of Android code coverage support as well as Sonar support pretty much. sigh

like image 235
Thomas Keller Avatar asked Sep 20 '12 06:09

Thomas Keller


People also ask

What is the best code coverage?

With that being said it is generally accepted that 80% coverage is a good goal to aim for. Trying to reach a higher coverage might turn out to be costly, while not necessary producing enough benefit. The first time you run your coverage tool you might find that you have a fairly low percentage of coverage.

What is Android test coverage?

Android Studio has a built-in feature that allows you to run tests with code coverage. Simply navigate to the src/test/java folder and right click. Then select Run 'Tests in 'java'' with Coverage (awkward use of single quotes theirs not mine).


2 Answers

I have pushed a github repo that contains the same configuration as you mentionned in your question :

  • standard android testing + emma code coverage
  • robolectric + cobertura code coverage (btw thx, I thought cobertura was not compatible with robolectric)

and their inclusion in sonar. Only one at a time, but still the configuration is an interesting base to work on.

https://github.com/stephanenicolas/Quality-Tools-for-Android

A colleague and I have in mind to work on this issue with a very similar mindset as you do. We want to get better integration of different testing technologies to be available for Android projects and reporting to work in sonar as well.

If you want to join our effort, we would be happy to give you the rights to the repo and start working with you.

Stéphane

-- Update

Since march 2013, we also propose a unified configuration to use Jacoco offline instrumentation for both robolectric and standard junit tests and get results displayed simultanously in Sonar.

like image 118
Snicolas Avatar answered Oct 02 '22 14:10

Snicolas


You can use the robolectric framework. It will allow you to run JUnit Tests on the Java VM instead of using Android Junit Tests that run on the Dalvik VM. This will allow you to use any standard coverage Tool out there (EclEmma, CodeCover, Cobertura, etc.). It's easy to configure and runs stable (What you can't say from the Clover tool).

like image 42
bla Avatar answered Oct 02 '22 12:10

bla