您的位置:首页 > 产品设计 > UI/UE

A template build.xml for running junit test by ant

2009-06-25 16:16 393 查看
Here is a template, you can modify the project name and replace the classpath with your own classpath.

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="runtests" name="AllocatedPart">
<!-- project common properties -->
<property name="app.name" value="AllocatedPart" />
<property name="allocatedpart.home" value="." />
<!-- build related -->
<property name="build.dir" value="${allocatedpart.home}/build" />
<property name="classes.dir" value="${build.dir}/src" />
<property name="test.dir" value="${build.dir}/test" />
<property name="src" value="src" />
<property name="test" value="test" />
<!-- library -->
<property name="lib.dir" value="${allocatedpart.home}/../lib" />
<property name="distributed.dir" value="${allocatedpart.home}/../distributed" />
<property name="thirdlib.dir" value="E:/libs" />
<!-- environment -->
<property environment="env" />
<!-- junit check -->
<target name="junit">
<available property="junit.present"
classname="junit.framework.TestCase" />
</target>
<!-- project classpath -->
<path id="project.class.path">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${distributed.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${thirdlib.dir}/spring2.0">
<include name="**/*.jar" />
</fileset>
<fileset dir="${thirdlib.dir}/strutstest">
<include name="**/strutstest.jar" />
</fileset>
<fileset dir="${thirdlib.dir}/struts/struts1.3.8">
<include name="**/*.jar" />
</fileset>
<fileset dir="${thirdlib.dir}/common">
<include name="**/*.jar" />
</fileset>
</path>
<!-- copy applicationContext*.xml -->
<target name="resource">
<copy todir="${test.dir}">
<fileset dir="${test}">
<include name="**/*.xml" />
<!-- other type of files can also be included here -->
</fileset>
</copy>
</target>
<!-- clean the build artifacts -->
<target name="clean">
<delete failonerror="false" includeemptydirs="true">
<fileset dir="${build.dir}" />
</delete>
</target>
<!-- compile the source code -->
<target name="compile" depends="junit">
<mkdir dir="${classes.dir}" />
<javac classpathref="project.class.path" debug="true" destdir="${classes.dir}" nowarn="false">
<classpath>
<pathelement location="${weblogic8.dir}/server/lib/weblogic.jar" />
</classpath>
<src path="${src}" />
<exclude name="**/CVS/**" />
</javac>
</target>
<!-- package the source code to jar -->
<target name="jar" depends="compile">
<mkdir dir="${build.dir}" />
<jar jarfile="${build.dir}/${app.name}.jar"
basedir="${classes.dir}" includes="com/**" />
</target>
<!-- compile the test case source code -->
<target name="compiletests" depends="jar">
<mkdir dir="${test.dir}" />
<javac srcdir="${test}" classpathref="project.class.path" destdir="${test.dir}">
<classpath>
<pathelement location="${build.dir}/${app.name}.jar" />
</classpath>
<include name="**/*.java" />
</javac>
</target>
<!-- run the test cases -->
<target name="runtests" depends="clean,compiletests,resource" if="junit.present">
<java fork="yes" classpathref="project.class.path" classname="junit.textui.TestRunner" taskname="junit"	failonerror="true">
<arg value="com.synnex.cis.part.biz.ValueListTest" />
<classpath>
<pathelement location="${build.dir}/${app.name}.jar" />
<pathelement location="${test.dir}" />
</classpath>
</java>
</target>
</project>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: