<?xml version="1.0" encoding="UTF-8"?>
<project name="junit-test" default="end">
<property name="src.dir" location="src"/>
<property name="test.src.dir" location="test"/>
<property name="build.dir" location="build"/>
<property name="build.classes" location="${build.dir}/classes"/>
<property name="build.test.dir" location="${build.dir}/test"/>
<property name="build.test.classes" location="${build.test.dir}/classes"/>
<property name="build.test.report" location="${build.test.dir}/report"/>
<!--一个类的情况<property name="run.test.class" value="ddloo.test.TestHelloWorld"></property>-->
<property name="run.test.class" value="**/Test*.class"></property>
<property name="lib.dir" location="lib"></property>
<path id="compile-path">
<fileset dir="${lib.dir}" includes="*.jar"></fileset>
</path>
<path id="compile-test-path">
<path refid="compile-path"></path>
<pathelement location="${build.classes}"/>
</path>
<path id="run-test-path">
<path refid="compile-test-path"></path>
<pathelement location="${build.test.classes}"/>
</path>
<target name="clean">
<echo>项目清理</echo>
<delete dir="${build.dir}"></delete>
</target>
<target name="init" depends="clean">
<echo>进行项目初始化</echo>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.test.dir}"/>
<mkdir dir="${build.test.classes}"/>
<mkdir dir="${build.test.report}"/>
</target>
<target name="compile" depends="init">
<echo>编译源文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${src.dir}" destdir="${build.classes}" classpathref="compile-path"></javac>
</target>
<target name="compile-test" depends="compile">
<echo>编译测试文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${test.src.dir}" destdir="${build.test.classes}" classpathref="compile-test-path"></javac>
</target>
<target name="run-test" depends="compile-test">
<echo>运行单元测试</echo>
<junit printsummary="true" haltonfailure="false"><!--haltonfailure为true则出问题就停止-->
<classpath refid="run-test-path"></classpath>
<formatter type="xml"/>
<!--只能测试一个测试类<test name="${run.test.class}"></test>-->
<batchtest todir="${build.test.report}">
<fileset dir="${build.test.classes}" includes="${run.test.class}"></fileset>
</batchtest>
</junit>
<junitreport todir="${build.test.report}">
<fileset dir="${build.test.report}" includes="TEST-*.xml"></fileset>
<report format="frames" todir="${build.test.report}/html"/>
</junitreport>
</target>
<target name="end" depends="run-test">
<echo>End</echo>
</target>
</project>