2

我无法定义为什么 emma 不生成运行时覆盖率数据。

运行测试时我忘记了什么?基于这篇文章: How to change Ant script with EMMA code-coverage so it can find runtime coverage data?

我将检测类放在类路径的顶部

蚂蚁艾玛.xml:

<!-- ====================================================================-->
<!-- EMMA SETUP -->
<!-- ====================================================================-->
<project name="Emma" basedir="." >
    <property file="./emma.properties" />
    <property name="emma.lib.dir"  location="${emma.home}/lib" />
    <property name="emma.build.dir" location="${build.dir}/emma" />
    <property name="emma.instr.dir" location="${emma.build.dir}/target" />
    <!-- directory which emma instrumentation classes will be written to -->
    <property name="emma.instr.src.dir" location="${emma.instr.dir}/src" />
    <property name="emma.instr.test.dir" location="${emma.instr.dir}/test" />
    <property name="emma.report.dir" location="${emma.build.dir}/report" />

    <!-- directory which emma coverage reports will be written to -->
    <property name="emma.data.dir" location="${emma.report.dir}/data" />
    <property name="emma.runtime.coverage.data.file" location="${emma.data.dir}/coverage.ec" />
    <property name="emma.coverage.merged.dir" location="${emma.data.dir}/final" />
    <property name="emma.coverage.file" location="${emma.coverage.merged.dir}/coverage-final.emma" />
    <property name="emma.filter" value="" />

    <path id="emma.lib.path" >
        <pathelement location="${emma.lib.dir}/emma.jar" />
        <pathelement location="${emma.lib.dir}/emma_ant.jar" />
    </path>

    <!-- Define which classes will be reported in the coverage reports (by default, we will include all classes and assume -->
    <!-- that your project's output folder is target/classes -->
    <path id="emma.coverage.classes" >
        <pathelement location="${build.src.dir}" />
        <pathelement location="${build.test.dir}" />
    </path>

    <path id="classpath.emma.run" >
        <pathelement location="${emma.instr.src.dir}" />
        <pathelement location="${emma.instr.test.dir}" />
        <pathelement location="${build.test.dir}" />
        <pathelement location="${build.src.dir}" />
        <path refid="classpath.src.compile" />
        <path refid="emma.lib.path" />
    </path>

    <taskdef resource="emma_ant.properties" classpathref="emma.lib.path" />

    <target name="emma-clean" >
        <delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.report.dir}"  />
        <delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.instr.dir}"  />
        <delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.build.dir}"  />
    </target>

    <target name="emma-init" depends="emma-clean">
        <mkdir dir="${emma.build.dir}" />
        <mkdir dir="${emma.report.dir}" />
        <mkdir dir="${emma.instr.dir}" />
        <mkdir dir="${emma.report.dir}" />
        <mkdir dir="${emma.data.dir}" />
        <mkdir dir="${emma.coverage.merged.dir}" />
    </target>

    <target name="emma-turn-on" description="turns on EMMA instrumentation/reporting">
        <property name="emma.enabled" value="true" />
        <property name="emma.verbosity.level" value="verbose" />
    </target>

    <target name="emma-instrumentation-src" depends="emma-turn-on, emma-init" description="do EMMA's src instrumentation">
        <emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
            <instr
                instrpath="${build.src.dir}"
                destdir="${emma.instr.src.dir}"
                metadatafile="${emma.data.dir}/metadata-src.em"
                merge="true"
                mode="fullcopy"
                >
                <filter value="${emma.filter.src}" />
            </instr>
        </emma>
    </target>

    <target name="emma-instrumentation-test" depends="emma-turn-on, emma-init" description="do EMMA's test instrumentation">
        <emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
            <instr
                instrpath="${build.test.dir}"
                destdir="${emma.instr.test.dir}"
                metadatafile="${emma.data.dir}/metadata-test.em"
                merge="true"
                mode="fullcopy"
                >
                <filter value="${emma.filter.test}" />
            </instr>
        </emma>
    </target>

    <target name="run-emma-instrumentation" depends="emma-instrumentation-src, emma-instrumentation-test" />

    <target name="emma-instrumentation" depends="emma-init, run-emma-instrumentation" description="do EMMA's merge instrumentation" />

    <target name="emma-do-test" depends="emma-instrumentation" >
        <junit printsummary="yes" haltonfailure="true" fork="true" >
            <classpath>
                <path refid="classpath.emma.run" />
            </classpath>
            <formatter type="plain" usefile="false" />
            <batchtest todir="${emma.report.dir}" >
                <fileset dir="${test.src.dir}" includes="**/*Test.java" />
            </batchtest>
            <jvmarg value="-Demma.coverage.out.file=${emma.runtime.coverage.data.file}" />
            <jvmarg value="-Demma.coverage.out.merge=true" />
        </junit>
        <echo message="Emma Test Result : ${emma.report.dir}" />
        <echo message="Emma file : ${emma.runtime.coverage.data.file}" />
    </target>

    <target name="emma-run-instrumentation-merge" depends="emma-do-test" description="do EMMA's instrumentation">
        <emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
            <merge outfile="${emma.coverage.file}" >
                <fileset dir="${emma.data.dir}" includes="*.em, *.ec" />
            </merge>
        </emma>
    </target>

    <target name="emma-run-report" depends="emma-run-instrumentation-merge" >
        <emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}">
            <report sourcepath="${src.dir}" depth="all" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100" >
                <fileset dir="${emma.coverage.merged.dir}" >
                    <include name="*.emma" />
                </fileset>
                <xml outfile="${emma.report.dir}/coverage.xml" depth="all" columns="class,method,block,line,name" />
                <txt outfile="${emma.report.dir}/coverage.txt" depth="all" columns="class,method,block,line,name" />
                <html outfile="${emma.report.dir}/coverage.html" depth="all" columns="class,method,block,line,name" />
            </report>
        </emma>
    </target>

    <target name="run-emma" depends="emma-run-report" />
</project>

输出:

emma-run-instrumentation-merge:
    [merge] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
    [merge] input data path:
    [merge] {
    [merge]   C:\Temp\builds\Example\emma\report\data\metadata-src.em
    [merge]   C:\Temp\builds\Example\emma\report\data\metadata-test.em
    [merge] }
    [merge] processing input file [C:\Temp\builds\Example\emma\report\data\metadata-src.em] ...
    [merge]   loaded 40 metadata entries
    [merge] processing input file [C:\Temp\builds\Example\emma\report\data\metadata-test.em] ...
    [merge]   loaded 3 metadata entries
    [merge] 2 file(s) read and merged in 20 ms
    [merge]   merged metadata contains 43 entries
    [merge] merged/compacted data written to [C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma] {in 0 ms}
emma-run-report:
   [report] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
   [report] input data path:
   [report] {
   [report]   C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma
   [report] }
   [report] source path:
   [report] {
   [report]   D:\wkp\AppUtils\src
   [report] }
   [report] processing input file [C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma] ...
   [report]   loaded 43 metadata entries
   [report] 1 file(s) read and merged in 0 ms
   [report] nothing to do: no runtime coverage data found in any of the data files
run-emma:
BUILD SUCCESSFUL
Total time: 7 seconds

带调试的输出:

emma-do-test:
        [junit] Couldn't find junit/framework/TestCase.class
        [junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar
        [junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar
        [junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar
        [junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar
    fileset: Setup scanner in dir D:\wkp\AppUtils\libs with patternSet{ includes: [**/*.jar] excludes: [] }
    Finding class junit.framework.Test
    Loaded from D:\wkp\AppUtils\libs\junit-4.11.jar junit/framework/Test.class
    Class java.lang.Object loaded from parent loader (parentFirst)
    Class junit.framework.Test loaded from ant loader (parentFirst)
    Finding class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl
    Loaded from D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.class
    Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror loaded from parent loader (parentFirst)
    Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror$SummaryJUnitResultFormatterMirror loaded from parent loader (parentFirst)
    Class java.lang.Throwable loaded from parent loader (parentFirst)
    Finding class junit.framework.AssertionFailedError
    Loaded from D:\wkp\AppUtils\libs\junit-4.11.jar junit/framework/AssertionFailedError.class
    Class java.lang.AssertionError loaded from parent loader (parentFirst)
    Class junit.framework.AssertionFailedError loaded from ant loader (parentFirst)
    Class java.lang.ClassLoader loaded from parent loader (parentFirst)
    Class org.apache.tools.ant.AntClassLoader loaded from parent loader (parentFirst)
    Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror$JUnitTestRunnerMirror loaded from parent loader (parentFirst)
    Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask loaded from parent loader (parentFirst)
    fileset: Setup scanner in dir D:\wkp\AppUtils\test with patternSet{ includes: [**/*Test.java] excludes: [] }
        [junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
        [junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
        [junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
        [junit] '-Demma.coverage.out.merge=false'
        [junit] '-classpath'
        [junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
        [junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
        [junit] 'app.commons.enums.TypeFileSizeTest'
        [junit] 'filtertrace=true'
        [junit] 'haltOnError=false'
        [junit] 'haltOnFailure=true'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
        [junit] 'showoutput=false'
        [junit] 'outputtoformatters=true'
        [junit] 'logfailedtests=true'
        [junit] 'logtestlistenerevents=false'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.enums.TypeFileSizeTest.txt'
        [junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher3180808930350880484.properties'
        [junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit6882722104357253846.properties'
        [junit] 
        [junit] The ' characters around the executable and arguments are
        [junit] not part of the command.
    Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
    '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
    '-Demma.coverage.out.merge=false'
    '-classpath'
    'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
    'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
    'app.commons.enums.TypeFileSizeTest'
    'filtertrace=true'
    'haltOnError=false'
    'haltOnFailure=true'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
    'showoutput=false'
    'outputtoformatters=true'
    'logfailedtests=true'
    'logtestlistenerevents=false'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.enums.TypeFileSizeTest.txt'
    'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher3180808930350880484.properties'
    'propsfile=D:\wkp\AppUtils\ant\emma\junit6882722104357253846.properties'

    The ' characters around the executable and arguments are
    not part of the command.
        [junit] Running app.commons.enums.TypeFileSizeTest
        [junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.026 sec
        [junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
        [junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
        [junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
        [junit] '-Demma.coverage.out.merge=false'
        [junit] '-classpath'
        [junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
        [junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
        [junit] 'app.commons.utils.AppFileUtilsTest'
        [junit] 'filtertrace=true'
        [junit] 'haltOnError=false'
        [junit] 'haltOnFailure=true'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
        [junit] 'showoutput=false'
        [junit] 'outputtoformatters=true'
        [junit] 'logfailedtests=true'
        [junit] 'logtestlistenerevents=false'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppFileUtilsTest.txt'
        [junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher4273539226127863796.properties'
        [junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit7675821937325699249.properties'
        [junit] 
        [junit] The ' characters around the executable and arguments are
        [junit] not part of the command.
    Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
    '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
    '-Demma.coverage.out.merge=false'
    '-classpath'
    'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
    'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
    'app.commons.utils.AppFileUtilsTest'
    'filtertrace=true'
    'haltOnError=false'
    'haltOnFailure=true'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
    'showoutput=false'
    'outputtoformatters=true'
    'logfailedtests=true'
    'logtestlistenerevents=false'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppFileUtilsTest.txt'
    'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher4273539226127863796.properties'
    'propsfile=D:\wkp\AppUtils\ant\emma\junit7675821937325699249.properties'

    The ' characters around the executable and arguments are
    not part of the command.
        [junit] Running app.commons.utils.AppFileUtilsTest
        [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.239 sec
        [junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
        [junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
        [junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
        [junit] '-Demma.coverage.out.merge=false'
        [junit] '-classpath'
        [junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
        [junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
        [junit] 'app.commons.utils.AppSystemUtilsTest'
        [junit] 'filtertrace=true'
        [junit] 'haltOnError=false'
        [junit] 'haltOnFailure=true'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
        [junit] 'showoutput=false'
        [junit] 'outputtoformatters=true'
        [junit] 'logfailedtests=true'
        [junit] 'logtestlistenerevents=false'
        [junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppSystemUtilsTest.txt'
        [junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher2828995806384576666.properties'
        [junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit7199116178610816128.properties'
        [junit] 
        [junit] The ' characters around the executable and arguments are
        [junit] not part of the command.
    Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
    '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
    '-Demma.coverage.out.merge=false'
    '-classpath'
    'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
    'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
    'app.commons.utils.AppSystemUtilsTest'
    'filtertrace=true'
    'haltOnError=false'
    'haltOnFailure=true'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
    'showoutput=false'
    'outputtoformatters=true'
    'logfailedtests=true'
    'logtestlistenerevents=false'
    'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppSystemUtilsTest.txt'
    'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher2828995806384576666.properties'
    'propsfile=D:\wkp\AppUtils\ant\emma\junit7199116178610816128.properties'

    The ' characters around the executable and arguments are
    not part of the command.
        [junit] Running app.commons.utils.AppSystemUtilsTest
        [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.019 sec
         [echo] Emma Test Result : c:\temp\builds\AppUtils\emma\report
         [echo] Emma file : c:\temp\builds\AppUtils\emma\report\data\coverage.ec
4

2 回答 2

0

我第一次运行这个时,发生了这个错误::

    [junit] Running app.commons.enums.TypeFileSizeTest
    [junit] Testsuite: app.commons.enums.TypeFileSizeTest
    [junit] Tests run: 8, Failures: 0, Errors: 8, Time elapsed: 0.04 sec
    [junit] Tests run: 8, Failures: 0, Errors: 8, Time elapsed: 0.04 sec
    [junit] Testcase: POS_TEST_CONVERT_TO_EB took 0 sec
    [junit]     Caused an ERROR
    [junit] Expecting a stackmap frame at branch target 11
    [junit] Exception Details:
    [junit]   Location:
    [junit]     app/commons/enums/TypeFileSize.<init>(Ljava/lang/String;ILjava/lang/Integer;)V @4: ifnonnull
    [junit]   Reason:
    [junit]     Expected stackmap frame at this location.
    [junit]   Bytecode:
    [junit]     0000000: b200 8c59 c700 0757 b800 9605 323a 042a
    [junit]     0000010: 2b1c b700 62a 2db5 0007 1904 0304 54b1
    [junit]     0000020:   

其实我做了一个非常糟糕的假设,我做错了……

经过几天的思考并浪费了一些时间来理解问题..我找到了解决方案:在VM中添加一个参数:(对不起,我失去了参考..)

<jvmarg value="-XX:-UseSplitVerifier" />

- 最后我只需要修改我的“emma-do-test”任务:

<target name="emma-do-test" depends="emma-instrumentation" >
    <junit printsummary="withOutAndErr" haltonfailure="true" fork="true"  >
        <classpath>
            <path refid="classpath.emma.run" />
        </classpath>
        <formatter type="plain" usefile="false" />
        <batchtest todir="${emma.report.dir}" >
            <fileset dir="${test.src.dir}" includes="**/*Test.java" />
        </batchtest>
        <jvmarg value="-XX:-UseSplitVerifier" />
        <jvmarg value="-Demma.coverage.out.file=${emma.runtime.coverage.data.file}" />
        <jvmarg value="-Demma.coverage.out.merge=false" />
    </junit>
    <echo message="Emma Test Result : ${emma.report.dir}" />
    <echo message="Emma file : ${emma.runtime.coverage.data.file}" />
</target>
于 2015-07-01T01:15:14.283 回答
0

当您使用错误的命令生成报告时,您会收到此错误。大多数在线教程都在提倡错误的(可能是旧的)命令,即使我在使用以下命令生成报告时也遇到了这个错误:

{JAVA_HOME}\jre\lib\ext>java -cp emma.jar 艾玛报告 -r html -in coverage.em, {ALFRESCO_HOME}\coverage.ec
EMMA:处理输入文件...
EMMA:1 个文件在 60 毫秒内读取和合并
EMMA:无事可做:在任何数据文件中都找不到运行时覆盖率数据

该命令的正确用法是(标记命令中有额外的“-in”):

{JAVA_HOME}\jre\lib\ext>java -cp emma.jar emma report -r txt,html -in {JAVA_HOME}\jre\lib\ext\coverage.em -in C:\t1_tempSetup\Alfresco\coverage.ec 
EMMA:处理输入文件...
EMMA:在 70 毫秒内读取并合并了 2 个文件 EMMA:将 [txt] 报告写入 [{JAVA_HOME}\jre\lib\ext\coverage.txt] ...
EMMA:将 [html] 报告写入 [{JAVA_HOME}\jre\lib\ext\coverage\index.html]
于 2015-10-19T18:46:24.860 回答