I have an Android Maven project (let's call it parent_project) that contains various submodules: my_library_project, app_using_my_library_project, test_project and extra_lib.
So, the structure would be like this:
parent_project
* my_library_project (Android Library Project)
* app_using_my_library_project (Demo app that uses the Android Library Project)
* test_project (Project containing the tests instrumented against app_using_my_library_project)
* extra_lib
What I would like is to generate test coverage for my Android project using Maven (and not Ant, I am already able to generate code coverage reports using Ant, following these instructions: https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project).
I have no strong preference for the code coverage tool used but I would prefer EMMA, since seems the most common in the Android development world.
I am using android-maven-plugin (http://code.google.com/p/maven-android-plugin/) in its 3.0.0-alpha-12 version and I have already tried to put in the configuration of my parent's pom.xml the next:
<test>
<coverage>true</coverage>
<createreport>true</createreport>
</test>
But that does not produce the desired code coverage report.
So:
To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By integrating the JaCoCo plugin, the results of the code coverage analysis can be reviewed as an HTML report. The current version of the JaCoCo-Maven plugin can be downloaded from the MVN Repository.
We can configure the JaCoCo Maven plugin by following these steps: Add the JaCoCo Maven plugin to the plugins section of our POM file. Configure the code coverage report for unit tests. Configure the code coverage report for integration tests.
In this article, we will show you how to use a JaCoCo Maven plugin to generate a code coverage report for a Java project. JaCoCo is an actively developed line coverage tool, that is used to measure how many lines of our code are tested.
Code coverage is the measurement of how much of your source code your tests actually touch. In Android development, you can generate test coverage reports locally using JaCoCo, and then remotely store them using Codecov.
If you're going to stick with maven, and want a plugin for maven that will do the code-coverage job, I think Cobertura is a better choice, as Emma stable last build is from 2005.
Although in "Android Application Testing Guide" (a recent book from June this year) they talk about Emma and demonstrate how to use it for testing, I think people stick to it, because it's needed to build Android from source (and if Google use it for their own OS development, it should be the best, right?).
If you're not fanatically bound to Maven, I strongly recommend to try Robotium. Robotium has full support for Activities, Dialogs, Toasts, Menus, and Context Menus. It also supports code coverage (Ant based though, for now) and some people recognize it as one of the leading testing platforms for Android.
Edit:
According to the Cobertura site, it supports code coverage in Maven 1 and Maven 2 environments. Although, you can find examples with Maven 3 also. A problem exists between pom configurations of Maven 2 and Maven 3. It seems for the reporting to work you have to basically move your old reporting plugins into the configuration section of the new maven-site-plugin. (See the article for details).
Another option is to try and use Sonar with Maven. Sonar has cobertura embedded (also options to embedd EMMA) and some people state that they had successfully reported code coverage, despite they had problems using the "stand-alone" cobertura plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With