Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate test coverage while using Robolectric

I am using make for building and Robolectric as a framework for running Android tests. I would like to calculate coverage of my app. For instrumentation tests I used to use emmalib. What is the best way for me to set up coverage calculation in this case? I can't migrate to gradle or maven.

like image 959
gruszczy Avatar asked Jan 16 '15 01:01

gruszczy


2 Answers

Are you bound to Emma? How about using RoboElectric + Cobertura code coverage? (I think you could just use a CLI for the above combination)

So options

1.) RoboElectric + Cobertura - CLI alone probably for someone not on ANT

2.) JaCoCo might have some useful options

3.) Pure Android Testing + Emma/EclEmma

Useful Link trails to follow

Generating android code coverage though changes in build.xml and ant.properties

Android Gradle Code Coverage

https://intellectualcramps.wordpress.com/2013/08/18/code-coverage-of-robolectric-tests-using-jacoco/

https://bitbucket.org/ravidsrk/androidstarter

EDIT:

Well most of the tutorials I have come across use ant unfortunately, and I don't think it would be a bad idea for you to move to a recommended build system like Gradle so it opens up a lot options. But for JaCoCo you could take a look at here: https://intellectualcramps.wordpress.com/2013/08/18/code-coverage-of-robolectric-tests-using-jacoco/

UPDATE:

Moved this from comments to the answer section for information to anyone wanting to see this and because this is a bounty question

like image 177
Vrashabh Irde Avatar answered Nov 15 '22 05:11

Vrashabh Irde


One solution would be to use Cobertura to generate code coverage, which can be integrated in eclipse and also run by an ant build script.

A template project of such an integration can be found here: https://github.com/adgllorente/android-cobertura-boilerplate

Note that all of the magic happens in the build.xml of the Test project. Theses tasks should probably be generalised to a custom_rules.xml file so you can still use android to update your projects.

Finally, for Gradle you have many different options:

  • http://raptordigital.blogspot.nl/2014/08/code-coverage-reports-using-robolectric.html
  • http://chrisjenx.com/gradle-robolectric-jacoco-dagger/
  • https://stackoverflow.com/a/25037742/2771851

Note that you can always use Gradle as a secondary build system just to generate the coverage reports. (but a second build system will introduce a lot of overhead)

like image 37
Jeroen Mols Avatar answered Nov 15 '22 05:11

Jeroen Mols