如何更改Ant脚本与EMMA代码覆盖,因此它可以找到运行的覆盖数据?(How to change A

2019-09-28 02:32发布

我有以下脚本:

<?xml version="1.0" encoding="UTF-8"?>

<taskdef resource="emma_ant.properties">
    <classpath>            
        <pathelement location="lib/emma.jar" />
        <pathelement location="lib/emma_ant.jar" />
    </classpath>
</taskdef>

<target name="compile">
    <mkdir dir="build"/> <!-- vytvori adresar build -->
    <mkdir dir="build/classes"/>
    <mkdir dir="build/test"/>
    <javac destdir="build/classes" srcdir="src" debug="true" /> <!-- prelozi zdrojove kody -->
    <javac destdir="build/test" srcdir="test"> <!-- prelozi testy -->
        <classpath> <!-- pro prelozeni testu je potreba junit a prelozena aplikace -->
            <pathelement location="lib/junit-4.5.jar" />
            <pathelement location="build/classes" />
        </classpath>
    </javac>
</target>

<target name="build" depends="compile">
    <jar destfile="tetris.jar" basedir="build/classes"> <!-- zabali aplikaci do jaru -->
        <manifest>
            <attribute name="Main-Class" value="tetris.Main"/>
            <attribute name="Class-Path" value="lib/mysql-connector-java-5.1.6-bin.jar lib/derbyclient.jar"/>
        </manifest>
    </jar>
</target>

<target name="jar" depends="build"></target>

<target name="run" depends="compile">
    <java classname="tetris.Main" classpath="build/classes">  <!-- spusti aplikaci -->
        <classpath>
            <pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
            <pathelement location="lib/derbyclient.jar" />
        </classpath>
    </java>
</target>

<target name="instrument" depends="compile">
    <mkdir dir="build/instrumented"/>

    <emma verbosity="verbose"> <!-- vytvori tridy upravene pro sledovani coverage -->
        <instr instrpath="build/classes"
                destdir="build/instrumented"
                metadatafile="build/metadata.emma"
                merge="true" />
    </emma>
</target>

<target name="test" depends="instrument">
    <mkdir dir="reports" />
    <mkdir dir="reports/junit" />

    <junit printsummary="yes" haltonfailure="no" fork="true"> <!-- pusti JUnit testy -->
        <classpath>
            <pathelement location="build/test" />
            <pathelement location="build/classes" />
            <pathelement location="build/instrumented" />
            <pathelement location="lib/junit-4.5.jar" />
            <pathelement location="lib/emma.jar" />
            <pathelement location="lib/emma_ant.jar" />
        </classpath>

        <formatter usefile="false" type="brief" />
        <formatter type="plain"/>

        <batchtest fork="yes" todir="reports/junit"> <!-- reporty budou v adresari reports/junit -->
            <fileset dir="test">
                <include name="**/TetrisSuite.java"/>
            </fileset>
        </batchtest>
        <jvmarg value="-Demma.coverage.out.file=build/coverage.emma"/>
        <jvmarg value="-Demma.coverage.out.merge=true" />
    </junit>

    <emma enabled="true" verbosity="verbose"> <!-- vygeneruje report emmy -->
        <report sourcepath="src">
            <fileset dir="build" includes="*.emma" />

            <html outfile="reports/coverage.html" />
        </report>
    </emma>
</target>

<target name="clean">
    <delete dir="build"/> <!-- smaze adresar build -->
    <delete dir="reports"/>
    <delete file="tetris.jar"/>
</target>

它输出以下消息:

processing input file [...NetBeansProjects/Tetris3/build/metadata.emma] ...
  loaded 25 metadata entries
1 file(s) read and merged in 5 ms
nothing to do: no runtime coverage data found in any of the data files

出了什么问题,如何解决?

Answer 1:

它看起来像你拿起非仪器类。

可能是因为classpath中您junit任务具有编译的类( build/classes提前仪表(中build/instrumented )。 在类路径也许扭转这些?

编辑

我下载了艾玛,并设置了一个源类和一个测试类的基础工程。 我试着用的问题提供的构建来运行它。 我所做的唯一变化是包裹体在<project>test作为默认目标。 在运行时我得到了类似的消息,在这个问题:

[report] processing input file [/Users/mjc/stack_overflow/emma/build/metadata.emma] ...
[report]   loaded 1 metadata entries
[report] 1 file(s) read and merged in 6 ms
[report] nothing to do: no runtime coverage data found in any of the data files

然后,我设置的junit类路径把仪表类提前香草:

<classpath>
    <pathelement location="build/test" />
    <pathelement location="build/instrumented" />
    <pathelement location="build/classes" />
    <pathelement location="lib/junit.jar" />
    <pathelement location="lib/emma.jar" />
    <pathelement location="lib/emma_ant.jar" />
</classpath>

并重新运行:

[report] processing input file [/Users/mjc/stack_overflow/emma/build/coverage.emma] ...
[report]   loaded 1 coverage data entries
[report] processing input file [/Users/mjc/stack_overflow/emma/build/metadata.emma] ...
[report]   loaded 1 metadata entries
[report] 2 file(s) read and merged in 4 ms
[report]   merged metadata contains 1 entries
[report]   merged coverage data contains 1 entries
[report] writing [html] report to [/Users/mjc/stack_overflow/emma/reports/coverage.html] ...
[report]   report: processing package [default package] ...

看起来像固定对我来说。 我有一个测试运行:

[junit] Running SoTest
[junit] Testsuite: SoTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.081 sec
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.081 sec
[junit] 
[junit] ------------- Standard Output ---------------
[junit] EMMA: collecting runtime coverage data ...
[junit] ------------- ---------------- ---------------

如果你没有看到蚂蚁一样输出的任何行也许你有匹配,没有测试**/TetrisSuite.java模式?



文章来源: How to change Ant script with EMMA code-coverage so it can find runtime coverage data?