Code Coverage for Android (calabash-android BDD)

I test my Android application using calabash-android , which provides it with its own “test project” with a script that renames its package to reflect the application under test, and then uses the InstrumentationTestRunner subclass:

adb shell am instrument -w -e class sh.calaba.instrumentationbackend.InstrumentationBackend #{ENV['TEST_PACKAGE_NAME']}/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner 

I will accept any answer that allows me to generate a code coverage report similar to Emma or Cobertura for an Android application, with data collected during testing in calabash-android.

In an attempt to get Emma's job, I have ...

  • Tried to follow these instructions to get Maven to create my project (because it was too long since I used ant). The coverage.em file is created in target/emma
  • Calabad android script changed by adding " -e coverage true "
  • When I launch calabash-android, I finally see "Generated coverage data in /data/data/my.project/files/coverage.ec"
  • adb -e pull /data/data/my.project/files/coverage.ec coverage.ec

... so now I should be able to run:

  • java -cp $ANDROID_HOME/tools/lib/emma.jar emma report -r html -in target/emma/coverage.em,coverage.ec

but I get an error:

 EMMA: processing input files... java.io.UTFDataFormatException: malformed input around byte 107 

... Therefore, I assume that something is wrong with the android maven plugin , and I'm trying to figure out how to generate coverage.em . I ran " android update project -p . " And " ant emma " and " ant emma debug ", but I can't find the .em coverage area anywhere ...

... The generated build.xml file apparently implies that the coverage.em file is generated only when "ant emma test" is run, but I don’t think this will work because the test application is controlled by the calabad android.

In an attempt to get a Cobertura job, I have ...

  • Googled various forms of "cobertura android", but it looks like someone is out of luck.
  • Tried to configure cobertura profile in my maven maven file for tool classes, but (in Maven 3) I get
    • a whole bunch of warnings about log4j and ant with InnerClasses attributes and that I have to recompile them from the source
    • error com.jayway.maven.plugins.android.generation2: android-maven-plugin: 3.3.0: dex "ANDROID-040-001: Failed to execute: Command = / bin / sh -c -cd / path / to / myproject & java -jar $ ANDOID_HOME / platform-tools / lib / dx.jar --dex ... "

 EXCEPTION FROM SIMULATION: local variable type mismatch: attempt to set or access a value of type java.lang.Class using a local variable of type java.lang.reflect.Type[]. This is symptomatic of .class transformation tools that ignore local variable information. 

... This is probably why no one was able to get cobertura to work on Android?

+4
source share
1 answer

The problem is that maven-android-plugin uses version 2.1.5320 from emma, while Android tools use version 2.0.5312. As discussed here , these two versions are incompatible.

The fix consists only in using one version for two tools. I was able to get it working by cloning the maven-android-plugin repository, setting the emma dependency version to 2.0.5312 and installing it in my local repository. Make sure the emma dependency in your test project is also correct, and then you should be able to create coverage.

An alternative is that all tools use the latest version. I have not tested it, but it might work if you create report generation from maven, then the version will be the same. You can also download the latest version of emma and generate a report using the jar from this package.

+5
source

All Articles