其他分享
首页 > 其他分享> > Android的代码覆盖率(calabash-android BDD)

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

作者:互联网

我正在使用calabash-android测试我的android应用程序,它提供了自己的“测试项目”,脚本重命名它的包以反映被测试的应用程序,然后使用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时,我最终看到“生成的覆盖数据到/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”.和“蚂蚁艾玛”和“蚂蚁艾玛调试”,但我找不到coverage.em任何地方……

…生成的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:无法执行: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上工作?

解决方法:

问题是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生成报告.

标签:android,code-coverage,cobertura,emma
来源: https://codeday.me/bug/20190620/1248234.html