使用TeamCity构建android项目 - 测试和代码覆盖问题

时间:2012-03-06 08:55:51

标签: android ant teamcity code-coverage emma

我正在开发一个由.NET代码和android java项目组成的项目。我们正试图让两种类型的项目在一个TeamCity环境中运行。

.NET项目正在通过一些NUnit项目进行测试,我们使用DotCover生成覆盖率报告,所有项目似乎都在膨胀。现在,android / java项目正在使用ant runners构建,我们已经为生产和测试项目提供了一些构建脚本,而且问题似乎是创建了java覆盖报告。 / p>

我们已经使用以下ant目标创建了构建步骤:

clean emma debug install test

构建步骤设置为启用“Emma coverage runner”(选中“在coverage数据中包含源文件”选项)。

运行构建步骤时发生错误,在日志片段中说明以下内容(已附加完整日志文件)。另一个重要问题是android / java单元测试没有出现在构建的整体统计中。

这是日志snippit:

[16:37:52]: [aapt] Generating resource IDs...
[16:37:55]: [subant] -pre-compile
[16:37:55]: [subant] -compile (1s)
[16:37:55]: [-compile] do-only-if-manifest-hasCode (1s)
[16:37:55]: [do-only-if-manifest-hasCode] sequential (1s)
[16:37:55]: [sequential] if (1s)
[16:37:55]: [if] Adding debug=true parameter to javac task
[16:37:55]: [if] javac
[16:37:55]: [if] Compiling 1 source file to C:\BuildAgent\work\c588ac2d935670cb\MyAndroidProject\bin\classes
[16:37:55]: [if] EMMA: Instrumenting classes
[16:37:55]: [EMMA: Instrumenting classes] EMMA commandline: [-ix, -*Test*, -cp, C:\BuildAgent\work\c588ac2d935670cb\MyAndroidProject\bin\classes, -m, overwrite]
[16:37:55]: [EMMA: Instrumenting classes] EMMA: processing instrumentation path ...
[16:37:56]: [EMMA: Instrumenting classes] EMMA: instrumentation path processed in 265 ms
[16:37:56]: [EMMA: Instrumenting classes] EMMA: [167 class(es) instrumented, 0 resource(s) copied]
[16:37:56]: [EMMA: Instrumenting classes] EMMA: metadata merged into [C:\BuildAgent\work\c588ac2d935670cb\coverage.em] {in 15 ms}
[16:37:56]: [if] if
[16:37:56]: [if] echo
[16:37:56]: [echo] Instrumenting classes from C:\BuildAgent\work\c588ac2d935670cb\MyAndroidProject\bin/classes...
[16:37:56]: [if] emma
[16:37:56]: [emma] com.vladium.emma.EMMARuntimeException: [OUT_IO_FAILURE] exception occurred while writing output file [C:\BuildAgent\work\c588ac2d935670cb\coverage.em]:
[16:37:56]: [do-only-if-manifest-hasCode] The following error occurred while executing this line: C:\Android\android-sdk\tools\ant\build.xml:655: com.vladium.emma.EMMARuntimeException: [OUT_IO_FAILURE] exception occurred while writing output file [C:\BuildAgent\work\c588ac2d935670cb\coverage.em]:
[16:37:56]: [subant] The following error occurred while executing this line: C:\Android\android-sdk\tools\ant\build.xml:602: The following error occurred while executing this line: C:\Android\android-sdk\tools\ant\build.xml:655: com.vladium.emma.EMMARuntimeException: [OUT_IO_FAILURE] exception occurred while writing output file [C:\BuildAgent\work\c588ac2d935670cb\coverage.em]:
[16:37:56]: [Step 1/18] EMMA: Create Report (4s)
[16:38:00]: [EMMA: Create Report] Unable to find C:\BuildAgent\work\c588ac2d935670cb\coverage.ec, cannot create EMMA report
[16:38:00]: [Step 1/18] Process exited with code 1
[16:38:00]: [Step 1/18] Ant output:
[16:38:00]: [Step 1/18] at java.lang.reflect.Method.invoke(Method.java:601)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Task.perform(Task.java:348)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[16:38:00]: [Step 1/18] at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[16:38:00]: [Step 1/18] at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
[16:38:00]: [Step 1/18] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[16:38:00]: [Step 1/18] at java.lang.reflect.Method.invoke(Method.java:601)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Task.perform(Task.java:348)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Target.execute(Target.java:390)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Target.performTasks(Target.java:411)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Main.runBuild(Main.java:809)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[16:38:00]: [Step 1/18] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
[16:38:00]: [Step 1/18] Caused by: java.io.IOException: cannot merge new data into [C:\BuildAgent\work\c588ac2d935670cb\coverage.em]: created by another EMMA version [0.0.0]
[16:38:00]: [Step 1/18] at com.vladium.emma.data.DataFactory.persist(DataFactory.java:593)
[16:38:00]: [Step 1/18] at com.vladium.emma.data.DataFactory.persist(DataFactory.java:71)
[16:38:00]: [Step 1/18] at com.vladium.emma.instr.InstrProcessorST._run(InstrProcessorST.java:753)
[16:38:00]: [Step 1/18] ... 71 more
[16:38:00]: [Step 1/18] Total time: 6 seconds
[16:38:00]: [Step 1/18] Publishing artifacts
[16:38:00]: [Publishing artifacts] Paths to publish: [C:\BuildAgent\work\c588ac2d935670cb\coverage.ec, C:\BuildAgent\work\c588ac2d935670cb\coverage.em, C:\BuildAgent\work\c588ac2d935670cb\coverage.txt, C:\BuildAgent\work\c588ac2d935670cb\coverage\coverage.zip]
[16:38:00]: [Publishing artifacts] Artifacts path coverage.ec not found
[16:38:00]: [Publishing artifacts] Artifacts path coverage.txt not found
[16:38:00]: [Publishing artifacts] Artifacts path coverage/coverage.zip not found
[16:38:00]: [Publishing artifacts] Sending files
[16:38:00]: [Step 1/18] Failed to extract Emma coverage statistics from the coverage.txt, due to error: java.io.FileNotFoundException: C:\BuildAgent\work\c588ac2d935670cb\coverage.txt (The system cannot find the file specified)
[16:38:00]: [Step 1/18] Step Test Smart Client - Unit tests (Ant) failed

有没有人知道问题可能是什么?

顺便说一句,当我直接从命令行运行目标时,报告的构建没有任何问题。

此致    每

1 个答案:

答案 0 :(得分:6)

Android SDK使用的EMMA版本比Sonar EMMA插件使用的版本旧。

似乎代码覆盖率的编码方式在版本之间发生了变化,这就是Sonar无法识别格式的原因。

幸运的是,有人想出了一个代码转换器。这里更详细地描述了该问题: http://jira.codehaus.org/browse/SONARPLUGINS-1356

上述代码转换器的java代码也可以从那里下载。

你必须在运行Sonar之前对所有.em和.ec文件进行转码,它应该读得很好 - 经过试用和测试。