问题:测试(似乎)没有执行
步骤 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>
步骤 2:将测试编译为 bin
<target name="compileTest" depends="compile" description="compile jUnit Test cases ">
<javac srcdir="${test-dir}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" />
</target>
第 3 步:查找测试.class并运行它们
<target name="test" depends="compileTest">
<junit>
<formatter type="plain" usefile="false" />
<formatter type="plain" />
<batchtest>
<fileset dir="${bin}" includes="**/Test*.class" />
</batchtest>
</junit>
</target>
输出:
Buildfile: /Users/xx/Documents/repositories/app/build.xml
clean:
[delete] Deleting directory /Users/xx/Documents/repositories/app/build
[delete] Deleting directory /Users/xx/Documents/repositories/app/bin
init:
[mkdir] Created dir: /Users/xx/Documents/repositories/app/build
[mkdir] Created dir: /Users/xx/Documents/repositories/app/bin
compile:
[javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/build
[javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/bin
compileTest:
[javac] Compiling 24 source files to /Users/xx/Documents/repositories/app/bin
test:
dist:
[delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.jar
[jar] Building jar: /Users/xx/Documents/repositories/app/dist/app.jar
[copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist
[delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.war
[war] Building war: /Users/xx/Documents/repositories/app/dist/app.war
[copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist
BUILD SUCCESSFUL
Total time: 5 seconds
请问我错过了什么?
我相信你可以在junit
任务中使用batchtest
:
<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
任务元素的"类路径"。
用一个简单的项目进行了测试,使用相同的配置,我得到了简短的结果。我使用了Apache Ant 1.7.1。
像这样使用"batchtest":
<batchtest>
<fileset dir="${tst-dir}" includes="**/Test*.class" />
</batchtest>
这里提供的示例。
编辑:
有关打印摘要,请参阅 ant junit 任务不报告详细信息,这
请注意,您不再需要 junit 任务中的属性printsummary="yes"
和showoutput="true"
。格式化程序现在正在处理输出。
<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>