您的位置:首页 > 其它

敏捷开发学习之二_ant

2008-04-12 08:58 363 查看
注意:利用ant运行测试程序。


<?xml version="1.0"?>




<project name="agileJava" default="rebuildAll" basedir=".">


<property name="src.dir" value="${basedir}" />


<property name="build.dir" value="${basedir}classes" />


<property name="report.xml" value="${basedir}/junit/xml" />


<property name="report.html" value="${basedir}/junit/html" />




<path id="classpath">


<fileset dir="${src.dir}">


<include name="*.jar" />


</fileset>


<pathelement path="${build.dir}" />


</path>




<target name="init">


<mkdir dir="${build.dir}" />


<mkdir dir="${report.xml}" />


<mkdir dir="${report.html}"/>


</target>




<target name="build" depends="init" description="build all">


<javac srcdir="${src.dir}" destdir="${build.dir}" source="1.5" deprecation="on" debug="on" optimize="off" includes="**">


<classpath refid="classpath" />


</javac>


</target>


<!-- 运行测试用例,并生成xml-->


<target name="junitgui" depends="build" description="run junitgui">


<junit printsummary="yes" haltonfailure="no">


<classpath refid="classpath" />


<formatter type="xml" />


<batchtest fork="yes" todir="${report.xml}">


<fileset dir="${build.dir}" includes="**/AllTests.class" />


</batchtest>


</junit>


</target>


<!-- 由生成的xml,生成html-->


<target name="report" depends="junitgui">


<junitreport todir="${report.html}">


<fileset dir="${report.xml}">


<include name="TEST-*.xml"/>


</fileset>


<report todir="${report.html}"/>


</junitreport>


</target>


<target name="clean">


<delete dir="${build.dir}" />


<delete dir="${report.xml}" />


<delete dir="${report.html}"/>


</target>




<target name="rebuildAll" depends="clean,build,junitgui,report" description="rebuild all" />


</project>



由于前面的测试用例,是采用的junit4的标注。如果
在ant中使用junit4还是有点问题。因为ant1.6.5等以前的版本不支持junit4。
必须去下载ant1.7.下载http://ant.apache.org/bindownload.cgi

如果出现错误:

ould not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.

那:

you need to go into Eclipse then click on Window->Preferences->ant->Runtime,
then select 'Ant Home Entries (Default). Click on the button 'Add External JARs'.
Locate the junit.jar file you copied, select it and hit 'OK'. Hit 'Apply',
then 'OK' and try your ant task again. That should fix it.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐