Teamcity Enterprise (5.1.5) code coverage and emma
Hi. I need to configure code coverage for java project. When I tested (just running ant target) it on my computer - all worked fine, but when I am trying run code coverage project from Teamcity I always get next log:
EMMA: collecting runtime coverage data ...
[09:45:37]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203 sec
[09:45:37]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.203 sec
[09:45:37]: [junit] Testcase: test_Regression took 0.097 sec
[09:45:38]: [test] echo
[09:45:38]: [echo] C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build
[09:45:38]: [test] emma
[09:45:38]: [emma] processing input files ...
[09:45:38]: [emma] java.io.UTFDataFormatException: malformed input around byte 65
[09:45:38]: [emma] at java.io.DataInputStream.readUTF(DataInputStream.java:639)
[09:45:38]: [emma] at java.io.DataInputStream.readUTF(DataInputStream.java:547)
[09:45:38]: [emma] at com.vladium.emma.data.MetaData.readExternal(MetaData.java:227)
[09:45:38]: [emma] at com.vladium.emma.data.DataFactory.readEntry(DataFactory.java:770)
[09:45:38]: [emma] at com.vladium.emma.data.DataFactory.mergeload(DataFactory.java:461)
[09:45:38]: [emma] at com.vladium.emma.data.DataFactory.load(DataFactory.java:56)
[09:45:38]: [emma] at com.vladium.emma.report.ReportProcessor._run(ReportProcessor.java:175)
[09:45:38]: [emma] at com.vladium.emma.Processor.run(Processor.java:54)
[09:45:38]: [emma] at com.vladium.emma.report.reportTask.execute(reportTask.java:77)
[09:45:38]: [emma] at com.vladium.emma.emmaTask.execute(emmaTask.java:57)
[09:45:38]: [emma] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[09:45:38]: [emma] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
[09:45:38]: [emma] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[09:45:38]: [emma] at java.lang.reflect.Method.invoke(Method.java:597)
[09:45:38]: [emma] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[09:45:38]: [emma] at org.apache.tools.ant.Task.perform(Task.java:348)
[09:45:38]: [emma] at org.apache.tools.ant.Target.execute(Target.java:357)
[09:45:38]: [emma] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[09:45:38]: [emma] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[09:45:38]: [emma] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[09:45:38]: [emma] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[09:45:38]: [emma] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[09:45:38]: [emma] at org.apache.tools.ant.Main.runBuild(Main.java:758)
[09:45:38]: [emma] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[09:45:38]: [emma] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[09:45:38]: [emma] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[09:45:38]: [test] echo
[09:45:38]: [echo] C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build
[09:45:38]: EMMA: Create Report
[09:45:38]: [EMMA: Create Report] EMMA commandline: [-r, html,txt, -in, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.em,C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.ec, -Dreport.html.out.file=coverage/index.html, -Dreport.txt.out.file=C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\dependencies\src.Aspose.pdf, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\src\src.jr3.7, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\src\src.jr3.1]
[09:45:38]: [EMMA: Create Report] EMMA: processing input files ...
[09:45:38]: Process exit code: 0
[09:45:38]: Publishing artifacts
[09:45:38]: [Publishing artifacts] Paths to publish: [C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.ec, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.em, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage\coverage.zip]
[09:45:38]: [Publishing artifacts] Artifacts path trunk/build/coverage.txt not found
[09:45:38]: [Publishing artifacts] Artifacts path trunk/build/coverage/coverage.zip not found
[09:45:38]: [Publishing artifacts] Publishing files
[09:45:38]: Failed to extract Emma coverage statistics from the coverage.txt, due to error: java.io.FileNotFoundException: C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt (The system cannot find the file specified)
It is very important for me to fix this problem ASAP. Please help me.
Please sign in to leave a comment.
Did you enable EMMA coverage in TeamCity web UI, or emma task was configured in your build script?
Hi Pavel,
I configured emma task in build.xml script:
<target name="compile_test" depends="jar">
<delete dir="${dir.test.bin}"/>
<mkdir dir="${dir.test.bin}"/>
<javac srcdir="${dir.root}/test" destdir="${dir.test.bin}" debug="on" deprecation="on" source="1.5" target="1.5" encoding="UTF-8">
<classpath>
<pathelement location="${gl.path.build.tmp}/${gl.jar.file}_${DSTAMP}_jdk${compile.source}.jar"/>
<pathelement location="${dir.test}/dependencies/crimson.jar"/>
<pathelement location="${dir.test}/dependencies/junit.jar"/>
<pathelement location="${dir.test}/dependencies/serializer.jar"/>
<pathelement location="${dir.test}/dependencies/xalan.jar"/>
<pathelement location="${dir.test}/dependencies/xalan.jar"/>
<pathelement location="${dir.test}/dependencies/xercesImpl.jar"/>
<pathelement location="${dir.test}/dependencies/xml-apis.jar"/>
<pathelement location="${dir.test}/dependencies/xsltc.jar"/>
<pathelement location="./${dir.test}/dependencies/tools"/>
<pathelement location="${dir.root}/dependencies/lib.common/log4j-1.2.15.jar.jar"/>
<pathelement location="${dir.root}/dependencies/lib.common/commons-logging-1.0.4.jar"/>
<pathelement path="${dir.root}/dependencies/lib.jr3.7/"/>
</classpath>
</javac>
</target>
<target name="test" depends="compile_test">
<copy
file="${gl.path.build.tmp}/${gl.jar.file}_${DSTAMP}_jdk${compile.source}.jar"
tofile="${gl.path.build.tmp}/emma.jr.pdf.jar">
</copy>
<emma>
<instr instrpath="${gl.path.build.tmp}/emma.jr.pdf.jar"
mode="overwrite"
metadatafile="${dir.coverage}${file.separator}coverage.em"
>
<filter includes=""/>
</instr>
</emma>
<mkdir dir="${dir.testout}${file.separator}visualtestout"/>
<junit
fork="yes"
printsummary="yes"
showoutput="true"
maxmemory = "1024M">
<jvmarg value="-Dfile.encoding=UTF-8"/>
<test name="regression.Regression" fork="true"/>
<formatter type="plain" usefile="false" />
<classpath>
<fileset dir="${dir.test.lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/dependencies/lib.common">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/dependencies/lib.jr3.7">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/build-tmp">
<include name="emma.jr.pdf.jar"/>
</fileset>
<fileset dir="${dir.root}/misc/tools">
<include name="emma.jar"/>
</fileset>
<fileset dir="${dir.root}/misc/tools">
<include name="emma_ant.jar"/>
</fileset>
<pathelement location="${dir.test.bin}"/>
</classpath>
</junit>
<!--<copy
file="${basedir}/coverage.ec"
tofile="${dir.root}/coverage/coverage.ec">
</copy>-->
<echo message="${dir.coverage}"/>
<emma>
<report sourcepath="${dir.coverage}" depth="method" > <!--sourcepath="${dir.root}/src"-->
<fileset dir="${dir.coverage}" >
<include name="coverage.em" />
</fileset>
<fileset dir="${dir.coverage}" >
<include name="coverage.ec" />
</fileset>
<txt outfile="${dir.coverage}/coverage.txt" />
<xml outfile="${dir.coverage}/coverage.xml" />
<html outfile="${dir.coverage}/coverage.html" />
</report>
</emma>
<echo message="${dir.coverage}"/>
</target>
Setting from teamcity project, which is calling "test" target:
Java coverage runner: Emma
Coverage instrumentation parameters: -ix @codecoverage.lst
Include source files in coverage data: ON
Deploy artifacts to Artifactory: disabled
XML report processing: disabled
Do not pay attention on emma_test_lib. It is an empty node in build script
If you have your own Emma task in build script, you should not use TeamCity coverage, otherwise you'll have you class files instrumented two times. Try to disable TeamCity own coverage and run your build again.
Thx Pavel, coverage data was generated. But how can I show it to user?
Now, coverage.txt ... were generated to build folder. Do I need to set some specific path?
--I solved this problem. Just copied files to root folder.
But the question I still have: how can I show some stats in overview tab?
If you need both coverage statistics and report, you'll have to use TeamCity coverage only (you need to disable emma task in your build script).
Alternatively you can publish coverage report produced by emma as an artifact and define custom tab on the build to show it: http://confluence.jetbrains.net/display/TCD6/Including+Third-Party+Reports+in+the+Build+Results but in this case you won't have coverage statistics numbers.
I would suggest to go with the first option, to my opinion it is simpler.
Thx, Pavel. Probably I will do as you proposed.
Hi Pavel.
>If you need both coverage statistics and report, you'll have to use TeamCity coverage only (you need to disable emma task in your build script).
Please explain me, if it is not hard for you, what i have to remove/add in my build script and Teamcity properties, to make Teamcity generate coverage (I want show stats on Overview tab to users).
You should call the target from your build script which runs tests only. In the TeamCity web UI you can choose IDEA coverage or Emma coverage. IDEA coverage is preferrable because it does not modify class files on disk. Then you need to provide packages where you want to gather coverage and regexps where you do not want to have coverage (usually test classes should be excluded). After that TeamCity should be able to gather coverage automatically. Let me know if it works for you.
Hi Pavel. Thank you for monitoring this thread.
[04:44:42]: [compile_test] javac[04:44:43]: [javac] Compiling 23 source files to C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\classes[04:44:43]: [javac] C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\tools\com\aspose\pdf\jr3_1_0\jasperreports\ElementsExporter.java:214: warning: [deprecation] isStyledText() in net.sf.jasperreports.engine.JRCommonText has been deprecated[04:44:43]: [javac] asposeText.setIsHtmlTagSupported(text.isStyledText());[04:44:43]: [javac] ^[04:44:43]: [javac] C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\tools\com\aspose\pdf\jr3_7_0\jasperreports\ElementsExporter.java:223: warning: [deprecation] isStyledText() in net.sf.jasperreports.engine.JRCommonText has been deprecated[04:44:43]: [javac] asposeText.setIsHtmlTagSupported(text.isStyledText());[04:44:43]: [javac] ^[04:44:44]: [javac] Note: Some input files use unchecked or unsafe operations.[04:44:44]: [javac] Note: Recompile with -Xlint:unchecked for details.[04:44:44]: [javac] 2 warnings[04:44:44]: [compile_test] EMMA: Instrumenting classes[04:44:44]: [EMMA: Instrumenting classes] EMMA commandline: [-ix, @codecoverage.lst, -cp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\classes, -m, overwrite][04:44:44]: [EMMA: Instrumenting classes] EMMA: processing instrumentation path ...[04:44:44]: [EMMA: Instrumenting classes] EMMA: instrumentation path processed in 313 ms[04:44:44]: [EMMA: Instrumenting classes] EMMA: [16 class(es) instrumented, 0 resource(s) copied][04:44:44]: [EMMA: Instrumenting classes] EMMA: metadata merged into [C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.em] {in 22 ms}[04:44:44]: test[04:44:44]: [test] Adding emma to classpath of JUnitTask.[04:44:44]: [test] junit[04:44:44]: [junit] WARNING: multiple versions of ant detected in path for junit jar:file:/C:/BuildAgent/plugins/ant/lib/ant.jar!/org/apache/tools/ant/Project.class and jar:file:/C:/BuildAgent/work/d27cb84568f8a8bd/trunk/dependencies/lib.common/ant-1.7.1.jar!/org/apache/tools/ant/Project.class[04:44:45]: [junit] Running regression.Regression[04:44:45]: [junit] Testsuite: regression.Regression[04:44:45]: [junit] regression.Regression[04:44:45]: [regression.Regression] test_Regression[04:44:45]: [test_Regression] [Test Output]EMMA: collecting runtime coverage data ...You wrote:
>Then you need to provide packages where you want to gather coverage and regexps where you do not want to have coverage (usually test classes should be excluded).
Tell me please, how I can provide this packages? What I have to do particularly?
Do you mean coverage.lst, which contains smth like this:
+com.pdf.jr3_1_0.EditionType
+com.pdf.jr3_1_0.JrColor
+com.pdf.jr3_1_0.JrGraph
....
I set Emma coverage runner in Teamcity project properties.
Also I changed target of my build script (classes for which I want have coverage are located in emma.jr.pdf.jar):
<target name="compile_test">
<delete dir="${dir.test.bin}"/>
<mkdir dir="${dir.test.bin}"/>
<copy todir="${dir.root}/test/tools">
<fileset dir="${dir.root}/src/src.jr3.7"/>
</copy>
<copy todir="${dir.root}/test/tools">
<fileset dir="${dir.root}/src/src.jr3.1"/>
</copy>
<javac srcdir="${dir.root}/test" destdir="${dir.root}/test/classes" debug="on" deprecation="on" source="1.5" target="1.5" encoding="UTF-8">
<classpath>
<pathelement location="${gl.path.build.tmp}/${gl.jar.file}_${DSTAMP}_jdk${compile.source}.jar"/>
<pathelement location="${dir.test}/dependencies/crimson.jar"/>
<pathelement location="${dir.test}/dependencies/junit.jar"/>
<pathelement location="${dir.test}/dependencies/serializer.jar"/>
<pathelement location="${dir.test}/dependencies/xalan.jar"/>
<pathelement location="${dir.test}/dependencies/xalan.jar"/>
<pathelement location="${dir.test}/dependencies/xercesImpl.jar"/>
<pathelement location="${dir.test}/dependencies/xml-apis.jar"/>
<pathelement location="${dir.test}/dependencies/xsltc.jar"/>
<pathelement location="./${dir.test}/dependencies/tools"/>
<pathelement location="${dir.root}/dependencies/lib.common/log4j-1.2.15.jar.jar"/>
<pathelement location="${dir.root}/dependencies/lib.common/commons-logging-1.0.4.jar"/>
<pathelement path="${dir.root}/dependencies/lib.jr3.7/"/>
<fileset dir="${dir.root}/dependencies/lib.jr3.7">
<include name="**/*.jar" />
</fileset>
<fileset dir="${dir.root}/dependencies/lib.common">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="test" depends="compile_test">
<junit
fork="yes"
printsummary="yes"
showoutput="true"
maxmemory = "1024M">
<jvmarg value="-Dfile.encoding=UTF-8"/>
<test name="regression.Regression" fork="true"/>
<test name="regression.Regression_jr370" fork="true"/>
<formatter type="plain" usefile="false" />
<classpath>
<fileset dir="${dir.test.lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/dependencies/lib.common">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/dependencies/lib.jr3.7">
<include name="*.jar"/>
</fileset>
<fileset dir="${dir.root}/build-tmp">
<include name="emma.jr.pdf.jar"/>
</fileset>
<fileset dir="${dir.root}/misc/tools">
<include name="emma.jar"/>
</fileset>
<fileset dir="${dir.root}/misc/tools">
<include name="emma_ant.jar"/>
</fileset>
<pathelement location="${dir.test.bin}"/>
</classpath>
</junit>
</target>
Log i have got:
[04:44:42]: compile_test
[04:44:42]: [compile_test] mkdir
[04:44:42]: [mkdir] Created dir: C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\classes
[04:44:42]: [compile_test] copy
[04:44:42]: [copy] Copying 10 files to C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\tools
[04:44:42]: [compile_test] copy
[04:44:42]: [copy] Copying 9 files to C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test\tools
[04:44:42]: [compile_test] Adding debug=true parameter to javac task
[04:44:45]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.234 sec
[04:44:45]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.234 sec
[04:44:45]: [junit] Testcase: test_Regression took 0.113 sec
[04:44:46]: [junit] Running regression.Regression_jr370
[04:44:46]: [junit] Testsuite: regression.Regression_jr370
[04:44:46]: [junit] regression.Regression_jr370
[04:44:46]: [regression.Regression_jr370] test_jr370
[04:44:50]: [test_jr370] [Test Output]
EMMA: collecting runtime coverage data ...[04:44:51]: [test_jr370] [Test Error Output]
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.[04:44:51]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5.591 sec
[04:44:51]: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 5.591 sec
[04:44:51]: [junit] Testcase: test_jr370 took 5.465 sec
[04:44:51]: EMMA: Create Report
[04:44:51]: [EMMA: Create Report] EMMA commandline: [-r, html,txt, -in, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.em,C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.ec, -Dreport.html.out.file=coverage/index.html, -Dreport.txt.out.file=C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\dependencies\src.Aspose.pdf, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\test, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\src\src.jr3.7, -sp, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\src\src.jr3.1]
[04:44:51]: [EMMA: Create Report] EMMA: processing input files ...
[04:44:52]: Process exit code: 0
[04:44:52]: Publishing artifacts
[04:44:52]: [Publishing artifacts] Paths to publish: [C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.ec, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.em, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt, C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage\coverage.zip]
[04:44:52]: [Publishing artifacts] Artifacts path trunk/build/coverage.txt not found
[04:44:52]: [Publishing artifacts] Artifacts path trunk/build/coverage/coverage.zip not found
[04:44:52]: [Publishing artifacts] Publishing files
[04:44:52]: Failed to extract Emma coverage statistics from the coverage.txt, due to error: java.io.FileNotFoundException: C:\BuildAgent\work\d27cb84568f8a8bd\trunk\build\coverage.txt (The system cannot find the file specified)
[04:44:52]: Publishing artifacts
[04:44:52]: [Publishing artifacts] Paths to publish: [trunk/**, teamcity-info.xml]
[04:44:52]: [Publishing artifacts] Publishing files
[04:54:14]: Build finished
Btw, I tried Idea coverage runner - it works for me. But if you can, explain me pls, what I am doing wrong with emma.
Thx