Ant build.xml 与 junit 测试的布局
在一个项目中,我有一个用于所有应用程序源代码的文件夹 src 和一个用于所有 junit 测试的不同文件夹 test(两者都具有模拟的包层次结构)。
现在我希望 Ant 可以运行 test 文件夹中的所有测试,bot 问题是现在还包含 src 文件夹中文件名中带有“Test”的文件。
这是 build.xml 中的测试目标:
<target name="test" depends="build">
<mkdir dir="reports/tests" />
<junit fork="yes" printsummary="yes">
<formatter type="xml"/>
<classpath>
<path location="${build}/WEB-INF/classes"/>
<fileset dir="${projectname.home}/lib">
<include name="servlet-api.jar"/>
<include name="httpunit.jar"/>
<include name="Tidy.jar"/>
<include name="js.jar"/>
<include name="junit.jar"/>
</fileset>
</classpath>
<batchtest todir="reports/tests">
<fileset dir="${build}/WEB-INF/classes">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
我已将测试文件夹添加到构建目标中:
<target name="build" depends="init,init-props,prepare">
<javac source="1.5" debug="true" destdir="${build}/WEB-INF/classes">
<src path="src" />
<src path="test" />
<classpath refid="classpath"/>
</javac>
</target>
In a project I have a folder src for all application source code and a different folder test for all junit test (both with a simular package hierarchy).
Now I want that Ant can run all tests in in test folder, bot the problem is that now also files in the src folder with "Test" in the filename are included.
This is the test target in the build.xml:
<target name="test" depends="build">
<mkdir dir="reports/tests" />
<junit fork="yes" printsummary="yes">
<formatter type="xml"/>
<classpath>
<path location="${build}/WEB-INF/classes"/>
<fileset dir="${projectname.home}/lib">
<include name="servlet-api.jar"/>
<include name="httpunit.jar"/>
<include name="Tidy.jar"/>
<include name="js.jar"/>
<include name="junit.jar"/>
</fileset>
</classpath>
<batchtest todir="reports/tests">
<fileset dir="${build}/WEB-INF/classes">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
And I have added the test folder to the build target:
<target name="build" depends="init,init-props,prepare">
<javac source="1.5" debug="true" destdir="${build}/WEB-INF/classes">
<src path="src" />
<src path="test" />
<classpath refid="classpath"/>
</javac>
</target>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将测试 .class 文件发布到单独的目录中,将此目录添加到
任务类路径并扫描该辅助目录中的**/*Test.class
。Publish test .class files into a separate directory, add this directory to
<junit>
task class path and scan that secondary directory for**/*Test.class
.