This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes ANT issues - Unable to create JUnit Reports- Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ANT issues - Unable to create JUnit Reports- Please help" Watch "ANT issues - Unable to create JUnit Reports- Please help" New topic
Author

ANT issues - Unable to create JUnit Reports- Please help

Micky Morgan
Greenhorn

Joined: Sep 20, 2006
Posts: 19
Hi,

I am having trouble creating JUnit Report using Ant

My Env: Java 1.5/Ant 1.6.5/Junit 4.1

The below summary shows that 2 Tests Passed...but the actual JUnit report says that both tetss Failed. Looks very wierd. Could anyone please help me to figureout the issue. I have noticed that I saw com.acme.MyTester has no methods to run ??? But it does have 2 tests and hence OK (2 tests)

*************
JUNIT summary
*************

init:

compile:
[javac] Compiling 1 source file to C:\UnitTests

Create_Jar:
[jar] Building jar: C:\UnitTests\JUnitTester.jar
Run:
[java] JUnit version 4.1
[java] ..
[java] Time: 6.406

[java] OK (2 tests)


Create_Report:
[echo] Running unit tests...
[junit] Running com.acme.MyTester
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
[junit] Test com.acme.MyTester FAILED
[junit] Running com.acme.MyTester
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
[junit] Test com.acme.MyTester FAILED
[junitreport] Transform time: 734ms

Here is the skeleton of my JUnit Tester...

*************
JUNIT Tester
*************


package com.acme;
import org.junit.*;

public class MyTester{


public void setUp() {
}

public void tearDown() {
}


public void testA() throws Throwable {

System.out.println("from testA");

}

public void testB() throws Throwable {

System.out.println("from testB");

}

}



*************
Ant Script
*************


Here is the skeleton of Ant build.xml to run and create JUnit Report for the above Tester


<project default="usage">

<target name="init">

<property name="Base.Dir" value="."/>
<property name="test.reports" value="./reports" />

<path id="ccp" description="The CLASSPATH for compiling and running">
<pathelement location="${Base.Dir}\JUnitTester.jar" />
<pathelement location="${Base.Dir}\junit-4.1.jar" />
<pathelement location="." />
</path>

</target>

<target name="compile" depends="init">
<javac srcdir="${Base.Dir}\source" includes="*.java" destdir="${Base.Dir}\source\" includeAntRuntime="no" fork="yes" debug="on">
<classpath refid="ccp" />
</javac>
</target>

<target name="Create_Jar" depends="compile">
<jar destfile="${Base.Dir}\source\JUnitTest.jar"
basedir="${Base.Dir}\source"
includes="**/*.class"
/>
</target>

<target name="Run" depends="Create_Jar" description="Run the jar file">
<java classname="org.junit.runner.JUnitCore" fork="yes" >
<arg value="com.acme.MyTester"/>
<classpath refid="ccp" />
</java>
</target>

<target name="Create_Report" depends="Run">

<echo message="Running unit tests... "/>

<junit printsummary="yes" haltonfailure="no">
<batchtest fork="yes">
<fileset dir="${Base.Dir}\source">
<include name="**/*.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="ccp" />
</junit>


<!-- generate test report -->

<junitreport todir="${test.reports}">
<fileset dir="${test.reports}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.reports}"/>
</junitreport>

</target>
</project>
[ November 20, 2006: Message edited by: Micky Morgan ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Micky,
Since the tests themselves work, I'm going to move this to our Ant forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ANT issues - Unable to create JUnit Reports- Please help
 
Similar Threads
[junit] java.lang.ClassNotFoundException: UserActivityTest
How to run JUNIT Tester with Ant
Not able run junit test cases from ANT
JUnit ant batch process failing
Could not create JUNIT HTML reports?