Ant and Junit all tests fail - java

I need to use ant to test my project develop in Java. I cannot make ant works properly. I haven't trully understood how to set the path for ant which files are needed to test correctly the project.
Which type of file is expecting? source or binary?
I am using this ant file to run the test :
<project name="acmetelecom" default="compile">
<property name="src" location="src/acme/com/acmetelecom" />
<property name="src" location="src/acme/com/acmetelecom" />
<property name="fit" location="fit" />
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="report" location="report" />
<property name="junit.report" location="report/junit" />
<property name="fit.report" location="report/fit" />
<path id="lib.classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
<include name="*" />
</fileset>
</path>
<path id="test.classpath">
<path refid="lib.classpath" />
<pathelement location="lib/junit/junit-4.4.jar" />
<pathelement location="lib/junit/junit-4.4-src.jar" />
<pathelement location="${bin}" />
</path>
<target name="compile">
<mkdir dir="${bin}" />
<javac srcdir="${src}" destdir="${bin}">
<classpath refid="lib.classpath" />
</javac>
</target>
<target name="junit" depends="compile">
<mkdir dir="${junit.report}" />
<junit printsummary="yes" fork="yes" haltonfailure="no">
<classpath refid="test.classpath" />
<formatter type="plain" />
<batchtest fork="yes" todir="${junit.report}">
<fileset dir="bin/com/acmetelecom">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</target>
<target name="fit" depends="compile">
<mkdir dir="${fit.report}" />
<java classname="fitlibrary.runner.FolderRunner" fork="yes"
failonerror="yes">
<classpath refid="test.classpath" />
<arg value="${fit}" />
<arg value="${fit.report}" />
</java>
<echo>Please see the FIT report page for more details</echo>
</target>
<target name="clean">
<delete dir="${bin}" />
<delete dir="${report}" />
</target>
</project>
I cannot see what I am doing wrong! The tests are in the same directory as the source code.

The root node of an Ant script is the project tag. An example I suggest starting simple... like get your Java source to compile, then add junit, etc.

You are writing .class files to ${bin}. Try to give that as argument in batchtest's fileset. There is no need to give packagedirectory paths anyway. */.class is going to check all directories.
<batchtest fork="yes" todir="${junit.report}">
<fileset dir="${bin}">
<include name="**/*Test.class" />
</fileset>
</batchtest>

Related

Power Mock Code Coverage using Corbetura, Ant 1.8.2 with JDK 1.5

I have searched for how to get coverage report for Corbetura for Power Mock Test Cases.
Found many answers for that, but still getting many issues.
I am using below configuration in my application:
Java (JDK) : 1.5.0_22
Eclipse : Indigo
Ant : 1.8.2
Corbetura Libraries : Tried with 2.1.1
(Still question which set of libraries to use ?)
Please help me on this.
Note: I am using JDK 1.5, I have found many links where it has mentioned configurations with JDK 1.6.
One more thing:
As of now I am not able to execute Ant script with <cobertura-instrument> tag.
Find below the build XML I am using.
I have removed some portion of build xml (I cannot share that due to confidentiality).
Please suggest what is the correct way, to do the code coverage report of Power Mock Test Cases using Corbetura and JDK 1.5 with Ant.
<project name="projName" basedir="." default="clean">
<description>
Project Desc
</description>
<!-- PROPERTIES -->
<property name="src.dir" location="src" />
<property name="test.dir" location="test" />
<property name="build.dir" location="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="testclasses.dir" value="${build.dir}/testclasses" />
<property name="instrumentedclasses.dir" value="${build.dir}/instrumentedclasses" />
<property name="dist.dir" location="dist" />
<property name="resources.dir" location="resources" />
<property name="libs.dir" value="lib" />
<property name="testReport.dir" location="testReport" />
<property name="cobertura.reports.dir" location="codecoverage" />
<property name="cobertura.datafile" value="${build.dir}/cobertura.ser" />
<property name="project.name" value="${ant.project.name}" />
<property name="cobertura.dir" value="D:\\corbetura_libs" />
<!-- PATHS -->
<path id="src.compile.classpath" description="classpath for compiling sources">
<fileset dir="${libs.dir}">
<include name="**/*.jar" />
<exclude name="**/junit*.jar" />
</fileset>
</path>
<path id="test.compile.classpath" description="classpath for compiling test-sources">
<pathelement location="${classes.dir}" />
<fileset dir="${libs.dir}">
<include name="**/*.jar" />
<exclude name="**/cobertura-2.1.1.jar" />
<exclude name="cobertura-dependencies/*.jar" />
</fileset>
</path>
<path id="test.runtime.classpath" description="classpath for running junit-tests">
<pathelement location="${testclasses.dir}" />
<pathelement location="${instrumentedclasses.dir}" />
<fileset dir="${libs.dir}">
<include name="**/*.jar" />
<exclude name="**/cobertura-2.1.1.jar" />
<exclude name="cobertura-dependencies/*.jar" />
<exclude name="cobertura-dependencies/hamcrest*.jar" />
</fileset>
</path>
<path id="cobertura.classpath" description="classpath for test-report">
<fileset dir="${cobertura.dir}">
<include name="cobertura*.jar" />
<include name="cobertura-dependencies/*.jar" />
</fileset>
</path>
<!-- taskdefs -->
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<!-- PREPARE -->
<target name="prepare" description="creating the needed directories for build and test report">
<delete dir="${build.dir}" />
<delete dir="${testReport.dir}" />
<delete dir="${cobertura.reports.dir}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${testclasses.dir}" />
<mkdir dir="${cobertura.reports.dir}" />
<mkdir dir="${testReport.dir}" />
</target>
<!-- COMPILE SOURCES -->
<target name="compile.sources" depends="prepare" description="compile the source ">
<!-- Compile the java code from ${src.dir} into ${build.dir} -->
<javac classpathref="src.compile.classpath" srcdir="${src.dir}" includeantruntime="false" source="1.5" target="1.5" destdir="${classes.dir}" debug="true" />
<copy todir="${classes.dir}">
<fileset dir="${resources.dir}" includes="*.properties" />
</copy>
</target>
<!-- CORBETURA INSTRUMENT CLASSES -->
<target name="instrument.classes" depends="compile.sources">
<cobertura-instrument todir="${instrumentedclasses.dir}" datafile="${cobertura.datafile}">
<includeclasses regex=".*" />
<instrumentationClasspath>
<pathelement location="${classes.dir}" />
</instrumentationClasspath>
</cobertura-instrument>
</target>
<!-- COMPILE TEST CASES -->
<target name="compile.tests" depends="instrument.classes" description="compile test classes">
<javac classpathref="test.compile.classpath" srcdir="${test.dir}" source="1.5" target="1.5" destdir="${testclasses.dir}" debug="true" includeantruntime="false" />
<copy todir="${testclasses.dir}">
<fileset dir="${resources.dir}" includes="*.properties" />
</copy>
</target>
<!-- RUN TEST CASES -->
<target name="run.tests" depends="compile.tests" description="execute junit test cases">
<junit haltonfailure="false" printsummary="yes" showoutput="yes" fork="true">
<!-- junit-specific -->
<formatter type="xml" />
<classpath refid="test.runtime.classpath" />
<batchtest fork="yes" todir="${testReport.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
<!-- cobertura-specific -->
<sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.datafile}" />
<classpath refid="cobertura.classpath" />
</junit>
<cobertura-report format="html" destdir="${cobertura.reports.dir}" datafile="${cobertura.datafile}" srcdir="${src.dir}" />
</target>
<!-- CREATE TEST CASE REPORT -->
<target name="report" depends="run.tests">
<junitreport todir="${testReport.dir}">
<fileset dir="${testReport.dir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${testReport.dir}" />
</junitreport>
</target>
</project>

What command do I execute to run this xml file

I have this XML code script and it says to use command prompt to execute it but everything I try doesnt work, it has a readme file which states
Clone the project with git or download the source zip from the github page and extract it.
Open the folder and run build.xml (this may require cmd to execute).
Wait for the build to complete and run DarkBot.jar from cmd with --help for args.
<project name="DarkBot" default="generate-protocols" basedir=".">
<target name="init">
<property name="outputDir" value="bin" />
<property name="protocolsDir" value="protocols" />
<property name="protocolsPackage" value="org.darkstorm.darkbot.minecraftbot.protocol" />
<property name="deployJar" value="DarkBot.jar" />
<property name="libraryDir" value="lib" />
<property name="tempDir" value="temp" />
<property name="mainClass" value="org.darkstorm.darkbot.mcwrapper.Main" />
<property name="antContribPath" value="build/ant-contrib-1.0b3.jar" />
</target>
<target name="clean" depends="init">
<delete file="${deployJar}" failonerror="false" />
<delete dir="${outputDir}" failonerror="false" />
<delete dir="${tempDir}" failonerror="false" />
</target>
<target name="compile" depends="clean">
<mkdir dir="${outputDir}" />
<javac encoding="UTF-8" destdir="${outputDir}" includeantruntime="false">
<src path="src/main/java" />
<src path="src/main/resources" />
<classpath>
<fileset dir="${libraryDir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
<copy todir="${outputDir}">
<fileset dir="src/main/java">
<exclude name="**/*.java" />
</fileset>
<fileset dir="src/main/resources">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target name="deploy" depends="compile">
<mkdir dir="${tempDir}" />
<unzip dest="${tempDir}">
<patternset>
<exclude name="META-INF/**" />
</patternset>
<fileset dir="${libraryDir}">
<include name="**/*.jar" />
</fileset>
</unzip>
<copy todir="${tempDir}">
<fileset dir="${outputDir}">
<include name="*" />
</fileset>
</copy>
<echo message="Manifest-Version: 1.0${line.separator}Class-Path: .${line.separator}Main-Class: ${mainClass}" file="${outputDir}/manifest.txt" />
<jar destfile="${deployJar}" basedir="${outputDir}" manifest="${outputDir}/manifest.txt" excludes="manifest.txt" />
<jar destfile="${deployJar}" basedir="${tempDir}" includes="**/**" update="true" />
<delete dir="${tempDir}" />
</target>
<target name="generate-protocols" depends="deploy">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${antContribPath}" />
</classpath>
</taskdef>
<mkdir dir="${protocolsDir}" />
<javac encoding="UTF-8" destdir="${protocolsDir}" includeantruntime="false">
<src path="src/main/protocols" />
<classpath>
<fileset file="${deployJar}" />
<fileset dir="${libraryDir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
<propertyregex property="protocolsFolder" input="src.main.protocols.${protocolsPackage}" global="true" regexp="\." replace="/" />
<pathconvert property="files" pathsep="${line.separator}">
<map from="${protocolsFolder}{$file.separator}" to="" />
<dirset dir="${protocolsFolder}">
<include name="*" />
</dirset>
</pathconvert>
<propertyregex property="protocolsFolder" override="true" input="${protocolsPackage}" global="true" regexp="\." replace="/" />
<for list="${files}" delimiter="${line.separator}" param="file">
<sequential>
<local name="protocolVersion" />
<basename property="protocolVersion" file="#{file}" />
<mkdir dir="${protocolsDir}/META-INF/services" />
<if>
<contains string="${protocolVersion}" substring="x" />
<then>
<propertyregex property="protocolVersion" override="true" input="${protocolVersion}" regexp="v([0-9]+)" select="\1" />
<echo message="${protocolsPackage}.v${protocolVersion}x.Protocol${protocolVersion}X$$Provider" file="${protocolsDir}/META-INF/services/${protocolsPackage}.ProtocolProvider" />
<jar destfile="${protocolsDir}/v${protocolVersion}x.jar" update="false" basedir="${protocolsDir}" includes="${protocolsFolder}/v${protocolVersion}x/**/**,META-INF/**/**" />
</then>
<else>
<propertyregex property="protocolVersion" override="true" input="${protocolVersion}" regexp="v([0-9]+)" select="\1" />
<echo message="${protocolsPackage}.v${protocolVersion}.Protocol${protocolVersion}$$Provider" file="${protocolsDir}/META-INF/services/${protocolsPackage}.ProtocolProvider" />
<jar destfile="${protocolsDir}/v${protocolVersion}.jar" update="false" basedir="${protocolsDir}" includes="${protocolsFolder}/v${protocolVersion}/**/**,META-INF/**/**" />
</else>
</if>
<delete dir="${protocolsDir}/META-INF" />
</sequential>
</for>
<propertyregex property="protocolBase" input="${protocolsPackage}" regexp="^([a-zA-Z][a-zA-Z0-9]+).*" select="\1" />
<delete dir="${protocolsDir}/${protocolBase}" />
</target>
Its an Ant build file. Download Ant and run the build targets listed E.g.
ant deploy
This looks like an ant build file, download and install an ant, try:
ant init deploy
or some other name in target tag.
Ant manual is here

dataDriven excel - ant via commandLine( testng ant webdriver)

I can run my tests via Ant in IDE.
But, While i try to run it from Command Line - it fails, because cant find the Excel from Resources
I added:
`<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>`
the file copied but still fail.
Looks like code doesnt look in correct place..
Any idea?
full build.xml:
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.5.jar"/>
</classpath>
</taskdef>
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="Resources" location="Resources"/>
<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>
<path id="classpath.base"/>
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}" />
<pathelement location="${srcdir}" />
<path refid="classpath.base" />
</path>
<target name="clean" >
<delete verbose="${full-compile}">
<fileset dir="${testdir}" includes="**/*.class" />
</delete>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}"
verbose="${full-compile}">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<testng outputdir=".test-output" classpathref="classpath.test"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>'
i found the problem.
in code i use the System.getProperty("user.dir") and when running from ant it finds my "user" folder.
So i can manually put there the excel ant it works.
Now, i need to find the way to change the System.getProperty("user.dir") to something that points to projects root

Cobertura + Junit

I have a question about cobertura in a connection with Ant scripts. I have already read these two articles on StackOverflow:
SONAR - Measure Code Coverage using Cobertura and Bamboo + sonar.dynamicAnalysis=reuseReports = 0% Rules Compliance
Furthermore, I have searched in the internet for a solution for my problem.
Now I hope you can help me.
The initial situation:
I have an Ant script to compile a library and then a test target. Now I have added cobertura. After some time I got it out that the classes and also the ser file is stored. The report is also generated, but with no coverage.
But now the problem is that the JUnit test will not work. The following error message can be found in the xml:
<testcase classname="com.***.***.***.***.***Test" name="test16" time="0.0">
<error message="com/***/***/***/***/***Rule" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: com/***/***/***/***/***Rule
at com.***.***.***.***.***Test.setUp(Unknown Source)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
I currently use the following code in the Ant script:
<project name="MainLIB" default="vbuild" basedir="./">
<path id="path.additionaltasks">
<fileset dir="../BUILD/antlib">
<include name="cobertura.jar" />
<include name="log4j-1.2.9.jar" />
<include name="asm-3.0.jar" />
<include name="asm-tree-3.0.jar" />
<include name="jakarta-oro-2.0.8.jar" />
</fileset>
</path>
<taskdef resource="tasks.properties" classpathref="path.additionaltasks" />
<path id="path.LIB">
<fileset dir="lib" includes="**/**.jar" />
</path>
<path id="path.UNITTEST">
<path refid="path.LIB" />
<pathelement path="build/cobertura/classes" />
<pathelement path="build/classes" />
<pathelement path="build/test-classes" />
</path>
<property name="dir.build" value="build" />
<property name="dir.build.classes" value="${dir.build}/classes" />
<property name="dir.build.cobertura" value="${dir.build}/cobertura" />
<property name="dir.build.cobertura.classes" value="${dir.build.cobertura}/classes" />
<property name="dir.build.test.classes" value="${dir.build}/test-classes" />
<property name="dir.build.test.report" value="${dir.build}/test-reports" />
<property name="dir.build.dist" value="${dir.build}/dist" />
<target name="vbuild" depends="build,test" description="Build and run tests" />
<target name="build" description="Compile classes and create .jar file in build/dist">
<delete dir="${dir.build}" />
<mkdir dir="${dir.build.classes}" />
<javac srcdir="src" classpathref="path.LIB" verbose="false" destdir="${dir.build.classes}" includeantruntime="false" includejavaruntime="false" debug="true">
</javac>
<mkdir dir="${dir.build.dist}" />
<jar jarfile="${dir.build.dist}/${jar.name}.jar" basedir="${dir.build.classes}">
</jar>
</target>
<target name="test" description="Compile and Run jUnit Tests">
<mkdir dir="${dir.build.test.classes}" />
<mkdir dir="${dir.build.test.report}" />
<javac srcdir="test" classpathref="path.UNITTEST" verbose="false" destdir="${dir.build.test.classes}" includeantruntime="false" includejavaruntime="false">
</javac>
<delete dir="${dir.build.cobertura}" />
<mkdir dir="${dir.build.cobertura}" />
<mkdir dir="${dir.build.cobertura.classes}" />
<cobertura-instrument todir="${dir.build.cobertura.classes}" datafile="${dir.build.cobertura}/cobertura.ser">
<fileset dir="${dir.build.classes}" />
</cobertura-instrument>
<junit printsummary="yes">
<classpath>
<!--<pathelement path="build/cobertura/classes" />-->
<path refid="path.UNITTEST" />
</classpath>
<formatter type="xml" />
<batchtest todir="${dir.build.test.report}">
<fileset dir="${dir.build.test.classes}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<cobertura-report format="xml" datafile="${dir.build.cobertura}/cobertura.ser" destdir="${dir.build.cobertura}/" />
<cobertura-report format="html" datafile="${dir.build.cobertura}/cobertura.ser" destdir="${dir.build.cobertura}/" />
</target>
The problem is, the classes are in the build/cobertura/classes directory. And I can't figure out, why Junit, can't find the classes
Your classpath:
<classpath>
<!--<pathelement path="build/cobertura/classes" />-->
<path refid="path.UNITTEST" />
</classpath>
Contains:
<path id="path.LIB">
<fileset dir="lib" includes="**/**.jar" />
</path>
<path id="path.UNITTEST">
<path refid="path.LIB" />
<pathelement path="build/cobertura/classes" />
<pathelement path="build/classes" />
<pathelement path="build/test-classes" />
</path>
But it also needs the cobertura jars, which you reference in path.additionaltasks. Cobertura instruments the class files with byte code manipluation. Those files still need the cobertura.jar dependency to work.
To fix it add the path.additionaltasks to junit:
<classpath>
<!--<pathelement path="build/cobertura/classes" />-->
<path refid="path.UNITTEST" />
<path refid="path.additionaltasks" />
</classpath>

Yet another Ant + JUnit classpath problem

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>

Categories