Running the Build File

That completes the build file that runs the JUnit tests in Project.java. You can see the final version of this file, build.xml in Example 5-1Example 5-1.

Example 5-3. Using Junit ch05/junit/build.xml

<?xml version="1.0" ?> <project default="main"> <property name="message" value="Building the project...." /> <property name="testsOK" value="Tested OK...." /> <property name="src" location="source" /> <property name="output" location="." /> <property name="results" location="results" /> <property name="jars" location="jars" /> <property name="dist" location="user" /> <property name="junit.fork" value="true"/> <target name="main" depends="init, compile, test, compress, deploy"> <echo> ${message} </echo> </target> <target name="init"> <mkdir dir="${output}" /> <mkdir dir="${results}" /> <mkdir dir="${jars}" /> </target> <target name="compile"> <javac srcdir="${src}" destdir="${output}" /> </target> <target name="test" depends="test1, test2, test3, test4, test5, test6"> <echo> ${testsOK} </echo> </target> <target name="test1" depends="compile"> <java fork="true" classname="junit.textui.TestRunner" classpath="${ant.home}/lib/junit.jar;."> <arg value="org.antbook.Project"/> </java> </target> <target name="test2" depends="compile"> <junit printsummary="yes" errorProperty="test.failed" failureProperty="test.failed" fork="${junit.fork}" haltonfailure="yes"> <formatter type="plain"/> <classpath path="."/> <test todir="${results}" name="org.antbook.Project"/> </junit> <fail ...

Get Ant: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.