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 Ant,运行所有jUnit测试_Java_Ant - Fatal编程技术网

Java Ant,运行所有jUnit测试

Java Ant,运行所有jUnit测试,java,ant,Java,Ant,问题是:测试(似乎)没有执行 步骤1:将源代码编译到bin <target name="compile" depends="init" description="compile the source "> <javac srcdir="${src}" destdir="${build}" includeantruntime="true" nowarn="yes" debug="true" /> <javac srcdir="${src}" destd

问题是:测试(似乎)没有执行

步骤1:将源代码编译到bin

<target name="compile" depends="init" description="compile the source ">
    <javac srcdir="${src}" destdir="${build}" includeantruntime="true" nowarn="yes" debug="true" />
    <javac srcdir="${src}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" />
</target>
<target name="compileTest" depends="compile" description="compile jUnit Test cases ">
    <javac srcdir="${test-dir}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" />
</target>
请问我遗漏了什么?

我相信您可以在
junit中使用任务:

<target name="test" depends="compileTest">
  <junit>
    <classpath>
      <pathelement location="bin" />    
      <pathelement location="lib/junit-4.10.jar"/>
    </classpath>    
    <batchtest>
       <fileset dir="${test}">
            <include name="**/*Test*" />
       </fileset>
    </batchtest>
    <formatter type="brief" usefile="false"/>
  </junit>
</target>   

注意以下事项:

  • fileset dir=“${test}”
    中,应指向测试的源目录
  • include name=“***Test*”
    中,不应指定
    .class
    扩展名;它应该是
    .java
    ,或者什么都不是
  • 您需要为
    junit
    task元素添加测试输出目录作为“类路径”
我用一个简单的项目进行了测试,使用相同的配置,我得到了简短的结果。我使用了ApacheAnt 1.7.1。

像这样使用“”:

  <batchtest>
    <fileset dir="${tst-dir}" includes="**/Test*.class" />
  </batchtest>

这似乎只运行testsrc中第一个包的测试。此外,是否有办法将报告简化为“运行500次测试,0次失败0次错误”之类的内容?更新了我的问题,将整个ANT脚本包括在内。非常感谢您继续关注这个问题。快速提问。。目前正在为每个测试包打印统计数据。我可以只得到一个所有测试的摘要吗?@nobeh-为什么不使用
.class
?当我将它指向
.java
文件时,我看不到任何区别
<target name="test" depends="compileTest">
  <junit>
    <classpath>
      <pathelement location="bin" />    
      <pathelement location="lib/junit-4.10.jar"/>
    </classpath>    
    <batchtest>
       <fileset dir="${test}">
            <include name="**/*Test*" />
       </fileset>
    </batchtest>
    <formatter type="brief" usefile="false"/>
  </junit>
</target>   
  <batchtest>
    <fileset dir="${tst-dir}" includes="**/Test*.class" />
  </batchtest>
<target name="test" depends="compileTest">
    <junit>
        <formatter type="plain" usefile="false" /> <!-- to screen -->
        <formatter type="plain" /> <!-- to file -->

        <batchtest>
            <fileset dir="${bin}" includes="**/Test*.class" />
        </batchtest>
    </junit>
</target>