Hi i'm quite new to using ant, my instructor wanted us to use it to do some tasks like build the class, run tests..etc
and i am really confused since i cant make the junit work. i have read several other posts and sources but it makes me even more confused.
the error i am getting is:
Testsuite: SolutionTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
Caused an ERROR
SolutionTest
java.lang.ClassNotFoundException: SolutionTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
this is my build file:
<project name="Solution" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="doc.dir" value="${build.dir}/documentation" />
<property name="test.dir" value="${build.dir}/test" />
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
</jar>
</target>
<target name="clean" depends="jar">
<delete dir="${classes.dir}"/>
</target>
<target name="doc" depends="clean">
<mkdir dir="${doc.dir}" />
<javadoc destdir="${build.dir}/documentation" sourcefiles="${src.dir}/*.java" />
</target>
<target name="junit" depends="doc">
<mkdir dir="${test.dir}" />
<junit printsummary="yes" haltonfailure="no">
<classpath location="." />
<test name="SolutionTest" haltonfailure="no" todir="${test.dir}" outfile="result">
<formatter type="plain" />
<formatter type="xml" />
</test>
</junit>
</target>
<target name="main" depends="clean, junit"/>
</project>
You should use <junit haltOnFailure="yes" haltOnError="yes" ...> if you want build to fail.
Alternatively you can use failureProperty and errorProperty
<junit failureProperty="test.failure" errorProperty="test.error">
<!-- your code here -->
</junit>
And verify if those properties was set
<target name="main" depends="clean, junit, verifyNoError, verifyNoFailure"/>
<target name="verifyNoError" if="test.error">
<fail message="JUnit test or tests errors."/>
</target>
<target name="verifyNoFailure" if="test.failure">
<echo message="I'm here. Now what?"/>
<fail message="JUnit test or tests failed."/>
</target>
Related
I am getting a ClassNotFound exception when I try to run my unit test.
Here is the .xml script for running the test.
<?xml version="1.0"?>
<project name="Embedded CST316 Project Test Build" default="targets" basedir=".">
<!-- set global properties for this build -->
<property name="src" location="airAutomation/src" />
<!-- <property name="test" location="airAutomation/test" /> -->
<property name="test" location="airAutomation/testAirUI/airUI/pkg" />
<property name="build" location="airAutomation/classes" />
<property name="test.dir" location="airAutomation/classes/tests" />
<property name="test.report.dir" location="airAutomation/testreport" />
<path id="junit.class.path">
<pathelement location="${build}" />
<pathelement location="airAutomation/lib/xbjlib-1.0.1.jar" />
<pathelement location="airAutomation/lib/junit-4.12.jar" />
<pathelement location="airAutomation/lib/hamcrest-core-1.3.jar" />
</path>
<target name="targets">
<!-- Display available targets -->
<echo message="targets are clean, prepare, compile, junit"/>
</target>
<target name="clean">
<!-- Delete the ${build} directory tree -->
<delete dir="${build}" />
<delete dir="${test.report.dir}" />
<!-- <delete dir="${test}" /> -->
</target>
<target name="prepare">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<!-- <mkdir dir="${test}" /> -->
<mkdir dir="${test.dir}" />
<mkdir dir="${test.report.dir}" />
</target>
<target name="compile" depends="clean, prepare"
description="Compile Unit Tests">
<!-- Compile all classes -->
<javac srcdir="${src}"
includeantruntime="false"
destdir="${build}" >
<classpath refid="junit.class.path" />
</javac>
<javac srcdir="${test}"
includeantruntime="false"
destdir="${test.dir}" >
<classpath refid="junit.class.path" />
</javac>
</target>
<target name="junit" depends="compile"
description="Execute Unit Tests">
<!-- Run Junit tests -->
<junit printsummary="yes" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<classpath>
<pathelement location="${test.dir}" />
</classpath>
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="airAutomation/testAirUI/airUI/pkg/">
<include name="**Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
</project>
Here is the output from the end of the xml.
<error message="roomTest" type="java.lang.ClassNotFoundException">
java.lang.ClassNotFoundException: roomTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
</error>
The test is in the folder "airAutomation/testAirUI/airUI/pkg/"
Would I need to specify this folder somewhere else (I created some folders to hold the output of the tests)?
I am trying to get Junit work with Ant. I have come across questions on the topic. I guess there is some small error somewhere but I can't figure it out. Here is my Build file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="IvleFileSync" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<!-- Variables used for JUnit testing -->
<property name="test.dir" location="test" />
<property name="test.report.dir" location="test-reports" />
<path id="junit-classpath">
<fileset dir="${test.dir}">
<include name = "*" />
</fileset>
</path>
<path id="files-classpath">
<fileset dir="/usr/lib" >
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<mkdir dir="${test.report.dir}" />
</target>
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<path refid="files-classpath" />
</classpath>
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/IvleFileSync-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="compile-test" depends="compile" description="compile the tests " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${test.dir}" destdir="${build}">
<classpath>
<path refid="files-classpath" />
</classpath>
</javac>
</target>
<target name="test" depends="compile-test" description="Execute Unit Tests" >
<junit printsummary="yes" fork="yes" haltonfailure="yes" showoutput="false">
<classpath >
<path refid="files-classpath" />
<path refid= "junit-classpath" />
</classpath>
<batchtest fork="yes" todir="${test.report.dir}/">
<formatter type="xml"/>
<fileset dir="${test.dir}">
<include name="*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${test.report.dir}" />
<delete dir="${dist}"/>
</target>
</project>
And I have test files in /test directory as well as i have put the jars in ANT_HOME/lib
That does not work and I get this error when I dig up the test-results/....xml
<error message="NewEmptyJUnitTest" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: NewEmptyJUnitTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
Thanks for helping me out...
The classpath for the junit task does not include the output of the compile-test target. Use something like the following for the JUnit classpath:
<classpath>
<pathelement path="${build}"/>
<path refid="files-classpath" />
<path refid="junit-classpath" />
</classpath>
You forgot to add your own classes ("build") to the "test" target.
I am using Eclipse Indigo. Not sure what is going on, but what I try to invoke the test suite from an ant build I get a ClassNotFoundException. However, if I right click on the JUnit Test class and run as Junit Test, it runs the tests fine. The error says that the file ./test/_ObservableSortUnitTests is not found. It gives the same error even if I give a full path to the file.
Here is my error:
Buildfile: /home/jason/Dev/ObservableSort/build.xml
Compile:
Test:
[junit] Testsuite: ./test/_ObservableSortUnitTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Caused an ERROR
[junit] ./test/_ObservableSortUnitTests
[junit] java.lang.ClassNotFoundException: ./test/_ObservableSortUnitTests
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:264)
[junit] at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
BUILD FAILED
/home/jason/Dev/ObservableSort/build.xml:75: Test ./test/_ObservableSortUnitTests failed
Total time: 1 second
Here is my ant script (disclaimer: I am very new to ant):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="Build" name="CS 151 Project Build Script" >
<!--ANT 1.7 is required -->
<property name="home" value="." />
<property name="src.dir" value = "${home}/src" />
<property name="dest.dir" value="${home}/Release" />
<property name="dir.build" value="${home}/lib" />
<property name="dir.javadoc" value="${dest.dir}/Javadoc" />
<property name="dir.classes" value="${dest.dir}/Classes" />
<property name="dir.junit.reports" value="${dest.dir}/Reports" />
<property name="test.suite.dir" value="${home}/test" />
<property name="test.suite.class" value ="${test.suite.dir}/_ObservableSortUnitTests" />
<path id="build.class.path">
<fileset dir="${dir.build}">
<include name="*.jar" />
</fileset>
</path>
<path id="test.class.path">
<pathelement location="${junit.test.suite}" />
</path>
<target name="Clean" description="Deletes all old files">
<delete dir="${dir.javadoc}" />
<delete dir="${dir.classes}" />
<delete dir="${dir.junit.reports}" />
</target>
<target name="Prepare" description="Creates all necessary directories">
<mkdir dir="${dir.javadoc}" />
<mkdir dir="${dir.classes}" />
<mkdir dir="${dir.junit.reports}" />
</target>
<target name="Compile">
<javac srcdir="${src.dir}" destdir="${dir.classes}" includeantruntime="true">
<classpath refid="build.class.path" />
</javac>
</target>
<target name="Full" description="Executes all build targets">
<antcall target="Clean" />
<antcall target="Prepare" />
<antcall target="Compile" />
<antcall target="Test" />
<antcall target="Build" />
<antcall target="Javadoc" />
<antcall target="run" />
</target>
<target name="Build" description="Creates executable jar" depends="Clean, Prepare, Compile">
<jar destfile="${dest.dir}/ObservableSort.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="cs151.project1.ObservableSortTest"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${home}/bin"/>
</jar>
</target>
<target name="Run" depends="Compile, Build">
<java jar="${dest.dir}/ObservableSort.jar" fork="true" />
</target>
<target name="Run with Unit Tests" depends="Compile, Build, Test">
<java jar="${dest.dir}/ObservableSort.jar" fork="true" />
</target>
<target name="Javadoc" description="Generate Javadoc" depends="Compile" >
<javadoc access="public" author="true" destdir="${dir.javadoc}" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="cs151.project1.sorters.insertionsort,cs151.project1.sorters.selectionsort,cs151.project1.Quantifiable,cs151.project1,cs151.project1.sorters.quicksort,cs151.project1.views" source="1.6" sourcepath="${src.dir}" splitindex="false" use="true" version="true"/>
</target>
<target name="Test" depends="Compile">
<junit>
<classpath refid="build.class.path" />
<classpath refid="test.class.path" />
<formatter type="plain" usefile="false" />
<test name="${test.suite.class}" haltonerror="true" />
</junit>
</target>
</project>
You are using the path to the testsuite class instead of the fully qualified name of the class.
Even though java classes are stored in filesystem folders, Java requires you to specify the package name dotted, not slashed.
Most likely the correct classname is test._ObservableSortUnitTests or maybe _ObservableSortUnitTests
If you specify the name of the test class in the junit task, then you need to use the fully qualifed class name, as Mark says. From JUnit task
<junit>
<test name="my.test.TestCase"/>
</junit>
If, however, you're using a batchtest, you can specify file names, but you need to add the .java on the end:
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
Stupid mistake: The JUnit classes were not yet compiled.
Solution:
Compile the project into a directory X
Compile the JUnit classes into a directory Y
Add the JUnit jar to directory Z
Inside the < test > tag, add directories X, Y, and Z to the classpath.
I am trying to run my JUnit test cases, but I keep getting the error :
Test com.capscan.accentsWorld FAILED
The report is created, but the test aren't run. Here is my Ant code:
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<fail if="testsfailed" message="tests failed" />
<delete dir="outputs/reports" />
<mkdir dir="outputs/reports" />
<junit printsummary="on" errorproperty="testsfailed">
<classpath>
<pathelement location="${build.com.capscan.accentsWorld}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="plain"/>
<test name="com.capscan.accentsWorld" haltonfailure="no" outfile="result">
<formatter type="xml"/>
</test>
<batchtest fork="yes" todir="src/com/capscan/accentsWorld/" >
<fileset dir="src/com/capscan/accentsWorld/">
<include name="**/Test*.java" />
</fileset>
</batchtest>
<formatter type="xml" />
</junit>
<junitreport todir="outputs/reports">
<fileset dir="outputs/reports">
<include name="TEST-*.xml" />
</fileset>
<report todir="outputs/reports" />
</junitreport>
</target>
and here is the output message on my console:
Buildfile: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\build.xml
create_run_jar:
[delete] Deleting directory C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports
[mkdir] Created dir: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports
[junit] Running com.capscan.accentsWorld
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.capscan.accentsWorld FAILED
[junitreport] Processing C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports\TESTS-TestSuites.xml to C:\DOCUME~1\ERGUNP~1\LOCALS~1\Temp\null1982495120
[junitreport] Loading stylesheet jar:file:/C:/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 1047ms
[junitreport] Deleting: C:\DOCUME~1\ERGUNP~1\LOCALS~1\Temp\null1982495120
BUILD SUCCESSFUL
Total time: 2 seconds
I don't see any <javac> task to compile the tests. Don't you have to do that first?
And I'm not sure where you think java.class.path is coming from, but I'd set it explicitly inside your Ant build.xml
Here's a generic build.xml that I use, including the testing task. Give it a look and see if it can help you:
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>
Try to run the ant in a verbose mode (ant -v). You should see more information.
Maybe you are missing something that is really basic like the #Test annotation in your test class (it happend to me that I only had methods annotated with #Ignore), or you have an error in a classpath. Show us fragment of your test class.
I'm developing an Eclipse SWT application using Eclipse. There are also some JUnit 4 tests, which test some DAO's. But when I try to run the tests via an ant build, all of the tests fail, because the test classes aren't found.
Google brought up about a million of people who all have the same problem, but none of their solutions seem to work for me -.- .
These are the contents of my build.xml file:
<property name="test.reports" value="./test/reports" />
<property name="classes" value="build" />
<path id="project.classpath">
<pathelement location="${classes}" />
</path>
<target name="testreport">
<mkdir dir="${test.reports}" />
<junit fork="yes" printsummary="no" haltonfailure="no">
<batchtest fork="yes" todir="${test.reports}" >
<fileset dir="${classes}">
<include name="**/Test*.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="project.classpath" />
</junit>
<junitreport todir="${test.reports}">
<fileset dir="${test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reports}" />
</junitreport>
</target>
The test classes are in the build-directory together with the application classes, although they are in some subfolders according to their packages.
Maybe this is important too: At first Ant complained that JUnit wasn't in its classpath, but since I put it there (with the eclipse configuration editor) it complains about JUnit being in its classpath twice.
WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/Users/as df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/Users/as%20df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
I've tried specifying each and every subdirectory, each and every class file, I've tried filesets and filelists, nothing seems to work.
Thanks for your help, I've been sitting for hours on this thing now...
I was getting this only when using the 'fork=true' option to the junit task. It was happening because my ANT_HOME had '..' in it (e.g. '/3rdparth/jboss/jboss-5/../tools'). Once I reduced that path, the 'multiple versions of ant' warning went away.
I had the same problem 'multiple versions of ant detected in path for junit'. The problem went away when I renamed by Eclipse_Home directory and removed special characters from it. The path had '[1]' in it which was causing the problem.
This Ant build.xml works fine for me. Check out the properties to see if the directory structure matches yours; adjust as needed.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>