首页 文章

Android的代码覆盖率(calabash-android BDD)

提问于
浏览
4

我正在使用calabash-android测试我的android应用程序,它提供了's own 2884453 , with a script that renames it' s包来反映被测试的应用程序,然后使用InstrumentationTestRunner子类:

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

我会接受任何答案,允许我为Android应用程序生成类似于Emma或Cobertura的代码覆盖率报告,并在calabash-android中测试时收集数据 .

为了让艾玛工作,我有......

  • 试图按照these instructions让Maven构建我的项目(因为我用了 Ant 已经太久了) . 在 target/emma 中生成 coverage.em 文件

  • 修改了calabash-android脚本,添加“ -e coverage true

  • 当我运行calabash-android时,我最终看到"Generated coverage data to /data/data/my.project/files/coverage.ec"

  • adb -e pull /data/data/my.project/files/coverage.ec coverage.ec

...所以现在我应该可以运行:

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

但是我收到一个错误:

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

...所以我认为android maven plugin有问题,我正在试图弄清楚如何生成 coverage.em 文件 . 我跑了“ android update project -p . " and " ant emma " and " ant emma debug ”,但 I can't find coverage.em anywhere ......

...生成的build.xml文件似乎暗示只有在运行“ant emma test”时才会生成coverage.em文件,但我认为这不会起作用,因为测试应用程序是由葫芦 - 机器人 .

为了让Cobertura工作,我有......

  • 用Google搜索各种形式的"cobertura android",但似乎没有人有任何运气 .

  • 尝试在我的Maven pom文件中配置cobertura配置文件来检测类,但是(在Maven 3中)我得到了

  • 关于log4j和ant具有"InnerClasses"属性的整堆警告,我应该从源代码重新编译它们

  • com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.0:dex "ANDROID-040-001: Could not 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.

...这可能是为什么没有人能让cobertura在Android上工作?

1 回答

  • 5

    问题是 maven-android-plugin 使用版本2.1.5320的emma,而Android工具使用版本2.0.5312 . 作为discussed here,这两个版本是不兼容的 .

    修复方法是仅在两个工具中使用单个版本 . 我已经能够通过克隆 maven-android-plugin repo,将emma依赖版本设置回2.0.5312并将其安装到我的本地存储库来使其工作 . 确保您的测试项目中的emma依赖项也是正确的,然后您应该能够生成一个coverage .

    另一种方法是确保所有工具都使用最新版本 . 我还没有对它进行过测试,但是如果你从maven生成报告,它可能会有效,那么版本就是一样的 . 您还可以下载最新版本的emma,并使用该软件包中的jar生成报告 .

相关问题