home *** CD-ROM | disk | FTP | other *** search
- Using JUnit4 with Ant
- =====================
- One of the common use case for JUnit is using it with Ant build system,
- as part of the build process of your source code.
-
- Explanation
- ------------
- To launch some JUnit4 TestCase from Ant, you need "ant" and "junit4" packages.
-
- You also need to add junit4.jar in nested <classpath> of your <junit> targets.
- There is no need to add it in CLASSPATH or to ANT_HOME/lib [1].
-
- [1]
- <URL:http://ant.apache.org/faq.html#delegating-classloader>
- "As of Ant 1.7 <junit> no longer requires you to have junit.jar in Ant's
- start-up classpath"
-
- <URL:http://ant.apache.org/manual/install.html#librarydependencies>
- "For example, as of Ant 1.7.0 you can run the <junit> task without junit.jar
- in Ant's own classpath, so long as it is included (along with your program
- and tests) in the classpath passed when running the task.
- Where possible, this option is generally to be preferred, as the Ant script
- itself can determine the best path to load the library from"
-
- This strategy also prevent unwanted clash with junit 3.x : you can launch
- multiple junit target, each with its own classpath.
-
- For detailed history, you could see #512530 and #543327 in Debian BTS.
-
-
- Sample
- ------
- Here is a Ant snippet for JUnit4 usage :
- ----------------------------------------------------------------
- <property name="main.classes" value="target/classes"/>
- <property name="test.classes" value="target/test-classes"/>
- <property name="lib.dir" value="/usr/share/java"/>
-
- <target name="test" depends="init, compile, compile-test">
-
- <junit printsummary="yes" haltonfailure="yes" haltonerror="yes">
-
- <classpath location="${main.classes}"/>
- <classpath location="${test.classes}"/>
- <classpath location="${lib.dir}/junit4.jar"/>
-
- <formatter type="plain" />
-
- <batchtest>
- <fileset dir="${test.classes}" includes="**/*TestCase"/>
- </batchtest>
-
- </junit>
-
- </target>
- ----------------------------------------------------------------
-