Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 只执行JUnit测试的Ant任务不运行测试_Java_Ant_Junit - Fatal编程技术网

Java 只执行JUnit测试的Ant任务不运行测试

Java 只执行JUnit测试的Ant任务不运行测试,java,ant,junit,Java,Ant,Junit,我试图创建一个ant目标,它只在项目上运行JUnit测试,不需要任何其他事先的操作。我使用Emma在另一个目标中检测这些,然后我有另一个目标在这些检测的类上进行字节码变异。所有这些都在起作用,在我执行了指令插入/变异步骤之后,我可以让JUnit在该目标中运行,但我需要有能力在编译指令变异链之外单独运行JUnit测试 我构建了一个如下所示的目标: <target name="mutant-test-run" description="Run tests with mutation appli

我试图创建一个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测试?

看起来您的文件集对于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>
根据页面上的示例,您可以使用:

<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>