Build Successfully but not running junit files using Apache Ant - java

I am new in Apache ant to build the project. In my Project i used MySQL,junit and hibernate library. I am working on bitbucket pipelines so some suggest use to ant. So i am creating the build.xml file and in there the proecess is clean,build,run junit test case. I did many research how to learn these things but i am stuck in some place. I am success in clean the directory and build also but i am stuck to check junit failure test case. I tried to run these test case in eclipse it shows that test case fail but if i run through ant it always say build successfully. I will provide my project structure .
+HiberTest
--HTest
--lib
--mysql
--junit
-- Hibernate..... so many library
--src
-com
-test
**so many junit files**
-com
-utils
**so many files**
--classpath
--.settings
--.project
**and many more files**
--build.xml
Here is my build.xml files
<project basedir="." default="junit" name="Hibernate test">
<property name="debuglevel" value="source,lines,vars" />
<property name="src.dir" location="HTest/src" />
<property name="build.dir" location="HTest/bin" />
<property name="target" value="1.8" />
<property name="source" value="1.8" />
<property name="test.dir" value="HTest/bin/com/test" />
<path id="classpath">
<pathelement location="bin" />
<pathelement location="HTest/lib/junit3.8.1.jar" />
<pathelement location="HTest/lib/antlr-2.7.7.jar" />
<pathelement location="HTest/lib/byte-buddy-1.10.7.jar" />
<pathelement location="HTest/lib/classmate-1.5.1.jar" />
<pathelement location="HTest/lib/dom4j-2.1.1.jar" />
<pathelement location="HTest/lib/FastInfoset-1.2.15.jar" />
<pathelement location="HTest/lib/hibernate-commons-annotations-5.1.0.Final.jar" />
<pathelement location="HTest/lib/hibernate-core-5.4.11.Final.jar" />
<pathelement location="HTest/lib/istack-commons-runtime-3.0.7.jar" />
<pathelement location="HTest/lib/jandex-2.1.1.Final.jar" />
<pathelement location="HTest/lib/javassist-3.24.0-GA.jar" />
<pathelement location="HTest/lib/javax.activation-api-1.2.0.jar" />
<pathelement location="HTest/lib/javax.persistence-api-2.2.jar" />
<pathelement location="HTest/lib/jaxb-api-2.3.1.jar" />
<pathelement location="HTest/lib/jaxb-runtime-2.3.1.jar" />
<pathelement location="HTest/lib/jboss-logging-3.3.2.Final.jar" />
<pathelement location="HTest/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar" />
<pathelement location="HTest/lib/mysql-connector-java-5.1.48.jar" />
<pathelement location="HTest/lib/stax-ex-1.8.jar" />
<pathelement location="HTest/lib/txw2-2.3.1.jar" />
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.dir}" />
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.launch" />
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" includeantruntime="false" source="${source}" target="${target}">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
</target>
<target name="junit" depends="build-project">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="classpath" />
<pathelement location="HTest/src/com/utils" />
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.dir}" includes="*.java" />
</batchtest>
</junit>
</target>
</project>
It always gives me this output:-
clean:
[delete] Deleting directory F:\Repository\Agile\HiberTest\HTest\bin
init:
[mkdir] Created dir: F:\Repository\Agile\HiberTest\HTest\bin
[copy] Copying 1 file to F:\Repository\Agile\HiberTest\HTest\bin
build-project:
[echo] Hibernate test: F:\Repository\Agile\HiberTest\build.xml
[javac] Compiling 3 source files to F:\Repository\Agile\HiberTest\HTest\bin
junit:
BUILD SUCCESSFUL
Total time: 1 second
I want to check that if junit test fail then stop the build process and if passes all without error and then i want to create executable jar files
Thanks in advance

The build starts in "build" and the hierarchical never call junit. Try to change:
<target depends="build-project" name="junit" />

Related

ant build.xml does not exist. Build failed

I am a beginner in Ant and GWT and I was creating a new Ant project in GWT by following the steps mentioned on this GWT page: webAppCreator under the Creating an Ant project section. I was able to create this project successfully but I got the error build.xml does not exist! in the Command Prompt log. I am unable to fix this problem even after following all the steps mentioned here : ant build.xml file doesn't exist.
Here is my Command Prompt log:
C:\Users\TEST>webAppCreator -junit D:\SELENIUM\junit-4.10.jar -out foo com.example.foo.Foo
Generating from templates: [sample, eclipse, readme, _eclipse-test, _sample-test, ant]
Created directory foo
Created directory foo\src
Created directory foo\src\com\example\foo
Created directory foo\src\com\example\foo\client
Created directory foo\src\com\example\foo\server
Created directory foo\src\com\example\foo\shared
Created directory foo\test
Created directory foo\test\com\example\foo
Created directory foo\war
Created directory foo\war\WEB-INF
Created directory foo\test\com\example\foo\client
Created file foo\src\com\example\foo\Foo.gwt.xml
Created file foo\src\com\example\foo\client\GreetingService.java
Created file foo\src\com\example\foo\client\GreetingServiceAsync.java
Created file foo\src\com\example\foo\client\Foo.java
Created file foo\src\com\example\foo\server\GreetingServiceImpl.java
Created file foo\src\com\example\foo\shared\FieldVerifier.java
Created file foo\war\WEB-INF\web.xml
Created file foo\war\Foo.css
Created file foo\war\Foo.html
Created file foo\war\favicon.ico
Created file foo\.classpath
Created file foo\.project
Created file foo\Foo.launch
Created file foo\README.txt
Created file foo\FooSuite-dev.launch
Created file foo\FooSuite-prod.launch
Created file foo\test\com\example\foo\FooJUnit.gwt.xml
Created file foo\test\com\example\foo\FooSuite.java
Created file foo\test\com\example\foo\client\FooTest.java
Created file foo\build.xml
C:\Users\TEST>ant build
Buildfile: build.xml does not exist!
Build failed
C:\Users\TEST>ant devmode
Buildfile: build.xml does not exist!
Build failed
Here is my build.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Foo" default="build" basedir=".">
<!-- Arguments to gwtc and devmode targets -->
<property name="gwt.args" value="" />
<!-- Configure path to GWT SDK -->
<property name="gwt.sdk" location="D:/GWT/gwt-2.8.1/gwt-2.8.1" />
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<pathelement location="${gwt.sdk}/gwt-dev.jar"/>
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar"/>
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar"/>
<fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
<!-- Add any additional non-server libs (such as JUnit) here -->
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet-deps.jar" />
<!-- Add any additional server libs that need to be copied -->
</target>
<target name="javac" depends="libs" description="Compile java source to bytecode">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.7" target="1.7" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
<copy todir="war/WEB-INF/classes">
<fileset dir="src" excludes="**/*.java"/>
</copy>
</target>
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler" maxmemory="512m">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="devmode" depends="javac" description="Run development mode (pass -Dgwt.args=-nosuperDevMode to fallback to classic DevMode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode" maxmemory="1g">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.sdk}/gwt-codeserver.jar"/>
</classpath>
<arg value="-startupUrl"/>
<arg value="Foo.html"/>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY, -logLevel DEBUG or -nosuperDevMode -->
<arg line="${gwt.args}"/>
<arg value="com.example.foo.Foo"/>
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="javac.tests" depends="javac" description="Compiles test code">
<javac srcdir="test" includes="**" encoding="utf-8"
source="1.7" target="1.7" nowarn="true"
destdir="war/WEB-INF/classes"
debug="true" debuglevel="lines,vars,source">
<classpath location="D:\SELENIUM\junit-4.10.jar"/>
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="test.dev" depends="javac.tests" description="Run development mode tests">
<mkdir dir="reports/htmlunit.dev" />
<junit fork="yes" printsummary="yes" haltonfailure="yes" maxmemory="256m">
<sysproperty key="gwt.args" value="-devMode -logLevel WARN -war www-test" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA.jar" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA-sources.jar" />
<pathelement location="D:\SELENIUM\junit-4.10.jar" />
</classpath>
<batchtest todir="reports/htmlunit.dev" >
<fileset dir="test" >
<include name="**/*Suite.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test.prod" depends="javac.tests" description="Run production mode tests">
<mkdir dir="reports/htmlunit.prod" />
<junit fork="yes" printsummary="yes" haltonfailure="yes" maxmemory="256m">
<sysproperty key="gwt.args" value="-logLevel WARN -war www-test" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA.jar" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA-sources.jar" />
<pathelement location="D:\SELENIUM\junit-4.10.jar" />
</classpath>
<batchtest todir="reports/htmlunit.prod" >
<fileset dir="test" >
<include name="**/*Suite.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test" description="Run development and production mode tests">
<antcall target="test.dev" />
<antcall target="test.prod" />
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="war" depends="build" description="Create a war file">
<zip destfile="Foo.war" basedir="war"/>
</target>
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/foo" failonerror="false" />
</target>
</project>
Can someone please help me to fix this issue?
It seems your build.xml is created in a foo folder.
See this output:
Created file foo\build.xml
Go to the foo directory and then run ant.
C:\Users\TEST>ant build
Buildfile: build.xml does not exist!
Build failed
It means build file is absent in TEST directory. Checking your logs you have one in the :\Users\TEST\foo. So you should navigate into foo than try command via terminal one more time.
if you are on Mac :
brew install ant;
brew install ivy;
ant ivy-bootstrap ;
then go to top of ant project;
run ant

ClassNotFoundException - when running ant-junit

I'm trying to create a Proof of concept for the actual application, The task is to run ant-junit tests without adding stuff to the global environment. I've achieved it so far in ant, but, I'm stuck with the following exception. ClassTest.java is the java class that has sample unit testcase. (Junit 3.0 style). I'm not sure why ant-junit does not find the class inspite of mentioning the paths in the batchrun task.
project structure
I get the following exception when running ant-junit task.
Testsuite: ClassTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
Caused an ERROR
ClassTest
java.lang.ClassNotFoundException: ClassTest
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
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)
My ant build.xml file is
<project name="Java project build" default="build">
<property name="project.local.directory" value="C:\Users\usrpao\workspace\Ant" />
<property name="src.path" value="${project.local.directory}/src" />
<property name="lib.path" value="${project.local.directory}/lib" />
<property name="dest.path" value="${project.local.directory}/target" />
<property name="junit.output.dir" value="${project.local.directory}/junit" />
<path id="classpath.test">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
<!--<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath refid="classpath.test" />
</taskdef> -->
<path id="MyProject.classpath">
<pathelement location="lib/ant-junit.jar" />
<pathelement location="lib/junit.jar" />
<pathelement location="bin/*.*"/>
</path>
<path id="lib.classpath">
<pathelement location="lib/ant-junit.jar" />
<pathelement location="lib/junit.jar" />
</path>
<target name="build" depends="clean">
<javac srcdir="${src.path}" destdir="${dest.path}" classpathref="lib.classpath">
</javac>
<antcall target="test">
</antcall>
</target>
<target name="clean">
</target>
<target name="test">
<pathconvert property="testoutput" refid="classpath.test" />
<echo>Path = ${testoutput}</echo>
<mkdir dir="${junit.output.dir}" />
<junit haltonerror="false" showoutput="true">
<classpath refid="MyProject.classpath">
</classpath>
<batchtest todir="${junit.output.dir}">
<formatter type="plain" />
<fileset dir="${src.path}/com/ant/test">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
Your classpath is referencing the bin directory while the classes are actually under the target directory. You should change the MyProject.classpath reference to include ${project.local.directory}/target:
<path id="MyProject.classpath">
<pathelement location="lib/ant-junit.jar" />
<pathelement location="lib/junit.jar" />
<dirset dir="${project.local.directory}">
<include name="target"/>
</dirset>
</path>
In addition, you should change the fileset element inside the junit task by removing the folders corresponding to the package name of the test class, otherwise you will still get a ClassNotFoundException:
<junit haltonerror="false" showoutput="true">
<classpath refid="MyProject.classpath">
</classpath>
<batchtest todir="${junit.output.dir}">
<formatter type="plain" />
<fileset dir="${src.path}"> <!-- remove com/ant/test corresponding to package name -->
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
From your folder structure it is evident that the class ClassTest.class is in target folder. so in class-path you should include following:
<pathelement path="target"/>
Hope this helps.

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

Ant and Junit all tests fail

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>

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>

Categories