11

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:

  • Is there any difference between the pom configuration for getting code coverage for a standard Java project and an Android project?
  • Do you know any example Android project using Maven that has code coverage?
  • Any hints on how to do this?
4
  • You get no report at all? You get a report that is irrelevant? You get a report that might be revelant but you don't like the answer? What are the symtoms of "don't get a report"? Commented Nov 7, 2011 at 4:01
  • Yes, I do not get test coverage report at all using Maven. I researched a lot and I did not find anything about configuring Maven to get test coverage in Android. I tried that configuration in my parent pom.xml, that seemed related to my problem and that I found here: code.google.com/p/maven-android-plugin/wiki/Changelog. I have not tried to include a dependency in the pom.xml for EMMA, like in a standard Java project, but I am unsure that it will work, thus my question. Commented Nov 7, 2011 at 7:59
  • I'm not specifically familar with Maven. Does it claim to have support for running tests on Android? If not, why are you expecting this to work? Commented Nov 7, 2011 at 8:02
  • Yes, Maven is able to build Android projects and automatically run all the tests, generating a report about the results (if they passed or not, how long they took...). But what I want, and I seem not to be able to do, is to get a code coverage report, that tells me which parts of the code have been exercised by the tests and which parts have not been tested yet. Commented Nov 7, 2011 at 8:20

2 Answers 2

2
+50

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.

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

7 Comments

Thanks for your suggestion, I will try to see if I can get what I want using Cobertura and report back what I find out. How I said in my question, currently I am using Ant for getting (some) test coverage, although I would prefer to be able to do everything with Maven. I am already using Robotium (tests in device, to see that everything really works as expected) and Robolectric (faster tests, more appropriate while developing), but the problem is that I was not able to put the Robolectric tests in the Android Test Project, so I don't know how to get a complete test coverage report with Ant.
which version of Maven do you use?
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100) and android-maven-plugin in its version 3.0.0-alpha-13.
the sonar project looks promising, tell back if you try it and get successful code coverage reports :).
You have to use Emma if you want coverage based on running code on the device itself because the Dalvik VM doesn't play nicely with live ClassLoader-based instrumentation jiggery-pokery. Emma is used to instrument the .class files, which are then translated (dexed) into Dalvik files. If there were a coverage tool that instrumented .class files before the dex step, it would probably work.
|
0

I could generate code coverage reported using emma maven plugin and display reports in sonar for an android application project. Just follow the configuration in https://code.google.com/p/maven-android-plugin/wiki/EmmaMaven. But for library project I get a 0% coverage. It doesn't generate the metadata files. However as soon I change the library project to package as an apk, it works like a charm. It runs the tests in a emulator(configured in jenkins) and shows the coverage reports. If you are looking out specifically for library project, this wont help. I will post if I find some solution which deals with library projects.

Comments

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.