仅执行 JUnit 测试的 Ant 任务不运行测试

发布于 2024-12-05 01:04:30 字数 3629 浏览 0 评论 0原文

我正在尝试创建一个 ant 目标,该目标仅在项目上运行 JUnit 测试,而不需要任何其他事先操作(不依赖)。我使用 Emma 在另一个目标中检测这些,然后我有另一个目标对这些检测的类进行字节码突变。所有这些都有效,在执行检测/突变步骤后,我可以让 JUnit 在该目标中运行,但我需要能够与此编译-仪器-突变链分开运行 JUnit 测试。

我建立了一个如下所示的目标:

<target name="mutant-test-run" description="Run tests with mutation applied">
    <path id="run.classpath">
        <pathelement location="${out.dir}" />
    </path>
    <mkdir dir="${reports}" />
    <junit printsummary="yes" fork="true">
        <classpath>
    <pathelement location="${out.instr.dir}" />
        <path refid="junit.classpath" />
    <path refid="famaLib.classpath" />
    <path refid="run.classpath" />
    <path refid="emma.lib" />
    </classpath>
        <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
        <jvmarg value="-Demma.coverage.out.merge=true" />

        <formatter type="plain" />
        <formatter type="xml" />

        <batchtest todir="${reports}">
            <fileset dir="${src.dir}">
                <include name="test1.java" />
                <include name="test2.java" />
                <include name="test3.java" />
                <include name="test4.java" />
                <include name="test5.java" />
            </fileset>
        </batchtest>
    </junit>
    <emma enabled="${emma.enabled}">
        <report sourcepath="${src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">           
            <fileset dir="${coverage.dir}">
                <include name="*.emma" />
            </fileset>
            <!-- for every type of report desired, configure a nested
         element; various report parameters can be inherited from the parent <report>
         and individually overridden for each report type:-->
            <txt outfile="${coverage.dir}/coverage.txt" depth="package" columns="class,method,block,line,name" />
            <xml outfile="${coverage.dir}/coverage.xml" depth="package" />
            <html outfile="${coverage.dir}/coverage.html" depth="method" columns="name,class,method,block,line" />
        </report>
    </emma>
</target>

然而,目标中的 jUnit 任务没有被执行,我得到的只是 mkdir 任务和 emma 任务的输出。

m1> ${ANT_HOME}/bin/ant -f nnbuild.xml -verbose mutant-test-run
Apache Ant(TM) version 1.8.2 compiled on July 5 2011
Buildfile: (Elided path here)/nnbuild.xml
Detected Java version: 1.6 in: /usr/lib64/jvm/java-1.6.0-sun-1.6.0/jre
Detected OS: Linux
parsing buildfile (Elided path)/nnbuild.xml with URI = file:(Elided path)/nnbuild.xml
    Project base dir set to: (Elided path)
    parsing buildfile jar:file:(Elided ANT_HOME path)/ant/lib/ant.jar!(Elided ANT_HOME path)/ant/antlib.xml with URI = jar:file:(Elided ANT_HOME path)/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
    Build sequence for target(s) `mutant-test-run' is [mutant-test-run]
    Complete build sequence is [mutant-test-run, emma, clean, init, compile, run, emma-run, merge, all, sofya, ]

    mutant-test-run:
     [mkdir] Skipping (Elided path)/reports because it already exists.
     [emma] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
       [report] processing input files ...
       [report] 1 file(s) read and merged in 48 ms
       [report] nothing to do: no runtime coverage data found in any of the data files

BUILD SUCCESSFUL
Total time: 0 seconds
m1> 

如何设置 ant 目标只进行 JUnit 测试?

I'm trying to make an ant target that only runs the JUnit tests on a project without any other prior actions (no depends). I'm using Emma to instrument these in another target, and then I have another target that does a bytecode mutation on these instrumented classes. All that is working and I can get JUnit to run in that target after I've performed the instrumentation/mutation steps but I need to have the ability to just run the JUnit tests separately from this compile-instrument-mutate chain.

I've build a target that looks like this:

<target name="mutant-test-run" description="Run tests with mutation applied">
    <path id="run.classpath">
        <pathelement location="${out.dir}" />
    </path>
    <mkdir dir="${reports}" />
    <junit printsummary="yes" fork="true">
        <classpath>
    <pathelement location="${out.instr.dir}" />
        <path refid="junit.classpath" />
    <path refid="famaLib.classpath" />
    <path refid="run.classpath" />
    <path refid="emma.lib" />
    </classpath>
        <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
        <jvmarg value="-Demma.coverage.out.merge=true" />

        <formatter type="plain" />
        <formatter type="xml" />

        <batchtest todir="${reports}">
            <fileset dir="${src.dir}">
                <include name="test1.java" />
                <include name="test2.java" />
                <include name="test3.java" />
                <include name="test4.java" />
                <include name="test5.java" />
            </fileset>
        </batchtest>
    </junit>
    <emma enabled="${emma.enabled}">
        <report sourcepath="${src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">           
            <fileset dir="${coverage.dir}">
                <include name="*.emma" />
            </fileset>
            <!-- for every type of report desired, configure a nested
         element; various report parameters can be inherited from the parent <report>
         and individually overridden for each report type:-->
            <txt outfile="${coverage.dir}/coverage.txt" depth="package" columns="class,method,block,line,name" />
            <xml outfile="${coverage.dir}/coverage.xml" depth="package" />
            <html outfile="${coverage.dir}/coverage.html" depth="method" columns="name,class,method,block,line" />
        </report>
    </emma>
</target>

The jUnit task within the target doesn't get executed however, all I get is the output from the mkdir task and the emma task.

m1> ${ANT_HOME}/bin/ant -f nnbuild.xml -verbose mutant-test-run
Apache Ant(TM) version 1.8.2 compiled on July 5 2011
Buildfile: (Elided path here)/nnbuild.xml
Detected Java version: 1.6 in: /usr/lib64/jvm/java-1.6.0-sun-1.6.0/jre
Detected OS: Linux
parsing buildfile (Elided path)/nnbuild.xml with URI = file:(Elided path)/nnbuild.xml
    Project base dir set to: (Elided path)
    parsing buildfile jar:file:(Elided ANT_HOME path)/ant/lib/ant.jar!(Elided ANT_HOME path)/ant/antlib.xml with URI = jar:file:(Elided ANT_HOME path)/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
    Build sequence for target(s) `mutant-test-run' is [mutant-test-run]
    Complete build sequence is [mutant-test-run, emma, clean, init, compile, run, emma-run, merge, all, sofya, ]

    mutant-test-run:
     [mkdir] Skipping (Elided path)/reports because it already exists.
     [emma] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
       [report] processing input files ...
       [report] 1 file(s) read and merged in 48 ms
       [report] nothing to do: no runtime coverage data found in any of the data files

BUILD SUCCESSFUL
Total time: 0 seconds
m1> 

How do you setup an ant target to only do JUnit tests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2024-12-12 01:04:30

看来您的文件集对于batchtest元素是错误的,我想您可能需要包含一个**:

<batchtest todir="${reports}">
    <fileset dir="${src.dir}">
        <include name="test1.java" />
        <include name="test2.java" />
        <include name="test3.java" />
        <include name="test4.java" />
        <include name="test5.java" />
    </fileset>
</batchtest>

从页面上的示例JUnit Task,您可以使用:

<batchtest fork="yes" todir="${reports.tests}">
    <fileset dir="${src.tests}">
        <include name="**/*Test*.java"/>
        <exclude name="**/AllTests.java"/>
    </fileset>
</batchtest>

其中**表示在任何子目录中。

另一个例子:

<batchtest todir="${collector.dir}" unless="hasFailingTests">
    <fileset dir="${collector.dir}" includes="**/*.java" excludes="**/${collector.class}.*"/>
</batchtest>

It looks like your fileset is wrong for the batchtest element, I think maybe you need to include a **:

<batchtest todir="${reports}">
    <fileset dir="${src.dir}">
        <include name="test1.java" />
        <include name="test2.java" />
        <include name="test3.java" />
        <include name="test4.java" />
        <include name="test5.java" />
    </fileset>
</batchtest>

From the examples on the page JUnit Task, you can use:

<batchtest fork="yes" todir="${reports.tests}">
    <fileset dir="${src.tests}">
        <include name="**/*Test*.java"/>
        <exclude name="**/AllTests.java"/>
    </fileset>
</batchtest>

Where the ** means in any sub-directory.

Another example:

<batchtest todir="${collector.dir}" unless="hasFailingTests">
    <fileset dir="${collector.dir}" includes="**/*.java" excludes="**/${collector.class}.*"/>
</batchtest>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文