Emma 报告覆盖率为 0% [英] Emma reports 0% coverage

查看:31
本文介绍了Emma 报告覆盖率为 0%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行单元测试时获得代码覆盖率.我使用标准的 android build.xml 运行 ant coverage 进行测试.

I want to get code coverage when running unit tests. I run ant coverage using standard android build.xml for tests.

测试运行良好.ant coverage 的最后一个字符串是

Tests run well. The last strings from ant coverage are

Tests run: 59,  Failures: 1,  Errors: 4

Generated code coverage data to /data/data/my.package/files/coverage.ec

但是coverage.ec 文件只有37 字节长,几乎是空的.

But the coverage.ec file is only 37 bytes long and is almost empty.

运行 emma 报告告诉

Running emma report on it tells

no collected coverage data found in any of the data files [all reports will be empty]

并在它的每个领域生成带有零的精美报告.

and generates beautiful report with ZEROES in every field of it.

我想 emma 应该产生更大的覆盖范围.ec.

I suppose that emma should generate a bigger coverage.ec.

我做错了什么?

--- 更新---

做了一些深入的挖掘.除了覆盖率结果生成之外,似乎大多数事情都很好.

Did some deep digging. It seems that most of things are well except coverage result generation.

1) 它编译了所有的东西

1) It compiles everything saying

[javac] /blabla/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 88 source files to /blabla/project/tests/instrumented/classes
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

2) 它正在为正在测试的项目执行 mode="overwrite".路径没问题.

2) It is doing <instr> with mode="overwrite" for the project that is under test. The path is ok.

-艾玛仪器:[echo] 检测来自/blabla/project/tests/instrumented/classes 的类...

-emma-instrument: [echo] Instrumenting classes from /blabla/project/tests/instrumented/classes...

因此,有一个 *.em 文件,其中包含 98 个类的元数据.

As a result, there is a *.em file with metadata for 98 classes.

3) 一些标准的 android 转换为 dex,打包为未对齐,zip 对齐.结果是/blabla/project/tests/instrumented/project-debug.apk.

3) Some standard android conversion to dex, package to unaligned, zip align. Result is /blabla/project/tests/instrumented/project-debug.apk.

4) 将此 project-debug.apk 安装到模拟器上.

4) Installing this project-debug.apk onto emulator.

5) 编译测试项目.编译:[javac]/blabla/android-sdk/android-sdk-linux_x86/tools/ant/main_rules.xml:384: 警告: 'includeantruntime' 未设置,默认为 build.sysclasspath=last;为可重复构建设置为 false[javac] 编译110个源文件到/blabla/project/tests/bin/classes

5) Compiling the tests project. compile: [javac] /blabla/android-sdk/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 110 source files to /blabla/project/tests/bin/classes

源文件包括所有以前的文件和测试(110 = 88 + 测试),如 build.properties 中所述(多个 source.dir 以;"分隔).

Source files include all the previous files plus tests (110 = 88 + tests), as stated in build.properties (multiple source.dir separated by ";").

6) 资源、Dex、签名、zip 对齐...结果是 projectTest-debug.apk

6) Resources, Dex, signing, zip align... Result is projectTest-debug.apk

7) 在模拟器上安装 projectTest-debug.apk.

7) Installing projectTest-debug.apk onto emulator.

8) 在指定coverage on"的情况下通过 am 运行测试.它说

8) Running tests through am where "coverage on" specified. It tells that

[exec] Generated code coverage data to /data/data/blabla.project/files/coverage.ec

9) 此coverage.ec 不包含相关数据.它有 37 个字节长.报告说

9) This coverage.ec contains no relevant data. It is 37 bytes long. Report on it tells that

processing input file [/home/ubuntu/projects/ppf2/workspace/PPF2/tests/coverage.ec] ...
loaded 0 coverage data entries
...
no collected coverage data found in any of the data files [all reports will be empty]

除了最后一步之外,一切对我来说似乎都很好.

Everything seems good for me except the last step.

推荐答案

最后,经过几个小时的斗争,问题解决了.解决方法很简单,出乎意料.

Finally, after many hours of fighting, question resolved. Resolution is very simple and unexpectable.

在 TEST 项目的 build.properties 中,我有类似的内容:

In build.properties of the TEST project I had something like:

tested.project.dir=..
env.WORKSPACE= /bla/bla
source.dir=${env.WORKSPACE}/first/src;${env.WORKSPACE}/second/src;${env.WORKSPACE}/andsoon/src;

但是!我不应该在这里指定 source.dir !指定tested.project.dir就足以成功编译测试项目.

But! I should NOT specify source.dir here! Specifying tested.project.dir is enough to compile test project successfully.

此外,如果我像这样在 TEST 项目中指定 source.dir - 测试运行良好,但 emma 报告零覆盖率,正如问题所述.

Moreover, if I specify source.dir in TEST project like this - tests run well but emma reports zero coverage, just as stated in question.

这篇关于Emma 报告覆盖率为 0%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆