473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JUnit Report using ANT. I NEED HELP!!!!

Hi, I'm currently working on getting junit and junireport to take some java files, convert it to xml and then display error messages / success rates etc in html which is one of the features of junitreport. I created a simple Math.java class which contains:

package test;

public class Math {

public int add(int a, int b) {

return a + b;
}

public int multiply(int i, int j) {

return i * j;
}


public int divide(int i, int j) {

return i / j;
}


public int subtract(int i, int j) {

return i - j;
}


public int Calculator () {

return 12;


}

}


... and a simple TestMath class:

package test;

import junit.framework.TestCase;

public class TestMath extends TestCase {

// public static void main (String [] args) {
// junit.textui.TestRunner.run(TestMath.class);
// junit.swingui.TestRunner.run(TestMath.class);
// }


Math nm = null;
Math nt = null;
Math nd = null;
Math ns = null;



protected void setUp() throws Exception {

nm = new Math();
nt = new Math();
nd = new Math();
ns = new Math();

}

protected void tearDown() throws Exception {


nm = null;
nt = null;
nd = null;
ns = null;

}


//Tests for Addition
public void testAdd() {

assertEquals(3, nm.add(1,2));
}


public void testAdd1() {

assertEquals(10, nm.add(5,5));
}


public void testAdd2() {

assertEquals(20, nm.add(16,4));
}




//Tests for Multiplication
public void testMultiply() {

assertEquals(12, nt.multiply(6,2));
}


public void testmultiply1() {

assertEquals(160, nt.multiply(2,80));
}

//Tests for Division
public void testdivide() {

assertEquals(25, nd.divide(50,2));
}


public void testdivide1() {

assertEquals(12, nd.divide(24,2));
}


//Tests for Subtraction
public void testsubtraction() {

assertEquals(620, ns.subtract(1000,380));
}

public void testsubtraction1() {

assertEquals(500, ns.subtract(1000,500));
}



}

Within ANT i have my junit and junitreport tasks:

<!-- ********************************* -->
<!-- * JUnit / JUnit Reports * -->
<!-- ********************************* -->


<description>
JUnit code to test aspects of the af. Will output .xml files
which will be converted to HTML format using junitreport.
</description>


<!-- top level targets -->


<target name="init" description="initialize the build environment (JUnit)" >
<!-- Create the time stamp -->
<tstamp/>
<!-- Create directory structures -->
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
<!--mkdir dir="${src}" /-->
</target>

<target name="compile" depends="init" description="compile the source code (JUnit) " >
<javac srcdir="workspace\af\src\test\DJK" destdir="${build}">

<!--move todir="workspace\af\src\test\DJK">
<fileset dir="workspace\af\src\test">
<include name="TestMath.java"/>
<include name="Math.java" />
<exclude name=""/>
</fileset>
</move-->

<classpath>

<fileset dir="lib">

<include name="**/*.jar"/>

</fileset>

</classpath>
</javac>
</target>


<target name="dist" depends="compile" description="generate the distributable files (JUnit) " >

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jar_name}" basedir="${build}"/>

</target>


<target name="cleanfiles" description="clean up files (JUnit)" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
</target>


<target name="run-tests" depends="compile" description="run the test suite (JUnit)" >

<junit printsummary="yes" haltonfailure="no" showoutput="yes" >
<classpath>
<pathelement path="${build}"/>
<fileset dir="dist">
<include name="**/*.jar"/>
</fileset>
</classpath>

<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="workspace\af\src\test\DJK">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>

<target name ="test" depends="run-tests" description="Run Tests (JUnit)">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>

<target name ="run" depends="" description="if this project can be run, run it (JUnit)" >
</target>

<!-- supporting targets -->

<target name="all" depends="clean, test">

</target>


........This does transform into html but with the following error message:

TestMath

java.lang.ClassNotFoundException: TestMath at java.net.URLClassLoader.findClass(URLClassLoader.j ava:375) at java.lang.ClassLoader.loadClass(ClassLoader.java:5 62) at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:442) at java.lang.ClassLoader.loadClass(ClassLoader.java:4 94) at java.lang.Class.forName1(Native Method) at java.lang.Class.forName(Class.java:180)

....The build is only successful because haltonfailure is set to no!

I know this is a big question, but any help would be very much greatly appreciated.

Danny Knights
ENGLAND.
Sep 15 '06 #1
3 5247
Hi Guys,
this script is running fine
but is there any option of running JUNIT report for particular method
in a particular test file.

if someone have any idea about it please let me know
Oct 31 '06 #2
Hi Danny Knights,
Did you got any solution for the below problem. because i am also facing the same problem. If you got solution please help me..

thanks
kishore


Hi, I'm currently working on getting junit and junireport to take some java files, convert it to xml and then display error messages / success rates etc in html which is one of the features of junitreport. I created a simple Math.java class which contains:

package test;

public class Math {

public int add(int a, int b) {

return a + b;
}

public int multiply(int i, int j) {

return i * j;
}


public int divide(int i, int j) {

return i / j;
}


public int subtract(int i, int j) {

return i - j;
}


public int Calculator () {

return 12;


}

}


... and a simple TestMath class:

package test;

import junit.framework.TestCase;

public class TestMath extends TestCase {

// public static void main (String [] args) {
// junit.textui.TestRunner.run(TestMath.class);
// junit.swingui.TestRunner.run(TestMath.class);
// }


Math nm = null;
Math nt = null;
Math nd = null;
Math ns = null;



protected void setUp() throws Exception {

nm = new Math();
nt = new Math();
nd = new Math();
ns = new Math();

}

protected void tearDown() throws Exception {


nm = null;
nt = null;
nd = null;
ns = null;

}


//Tests for Addition
public void testAdd() {

assertEquals(3, nm.add(1,2));
}


public void testAdd1() {

assertEquals(10, nm.add(5,5));
}


public void testAdd2() {

assertEquals(20, nm.add(16,4));
}




//Tests for Multiplication
public void testMultiply() {

assertEquals(12, nt.multiply(6,2));
}


public void testmultiply1() {

assertEquals(160, nt.multiply(2,80));
}

//Tests for Division
public void testdivide() {

assertEquals(25, nd.divide(50,2));
}


public void testdivide1() {

assertEquals(12, nd.divide(24,2));
}


//Tests for Subtraction
public void testsubtraction() {

assertEquals(620, ns.subtract(1000,380));
}

public void testsubtraction1() {

assertEquals(500, ns.subtract(1000,500));
}



}

Within ANT i have my junit and junitreport tasks:

<!-- ********************************* -->
<!-- * JUnit / JUnit Reports * -->
<!-- ********************************* -->


<description>
JUnit code to test aspects of the af. Will output .xml files
which will be converted to HTML format using junitreport.
</description>


<!-- top level targets -->


<target name="init" description="initialize the build environment (JUnit)" >
<!-- Create the time stamp -->
<tstamp/>
<!-- Create directory structures -->
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
<!--mkdir dir="${src}" /-->
</target>

<target name="compile" depends="init" description="compile the source code (JUnit) " >
<javac srcdir="workspace\af\src\test\DJK" destdir="${build}">

<!--move todir="workspace\af\src\test\DJK">
<fileset dir="workspace\af\src\test">
<include name="TestMath.java"/>
<include name="Math.java" />
<exclude name=""/>
</fileset>
</move-->

<classpath>

<fileset dir="lib">

<include name="**/*.jar"/>

</fileset>

</classpath>
</javac>
</target>


<target name="dist" depends="compile" description="generate the distributable files (JUnit) " >

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jar_name}" basedir="${build}"/>

</target>


<target name="cleanfiles" description="clean up files (JUnit)" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
</target>


<target name="run-tests" depends="compile" description="run the test suite (JUnit)" >

<junit printsummary="yes" haltonfailure="no" showoutput="yes" >
<classpath>
<pathelement path="${build}"/>
<fileset dir="dist">
<include name="**/*.jar"/>
</fileset>
</classpath>

<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="workspace\af\src\test\DJK">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>

<target name ="test" depends="run-tests" description="Run Tests (JUnit)">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>

<target name ="run" depends="" description="if this project can be run, run it (JUnit)" >
</target>

<!-- supporting targets -->

<target name="all" depends="clean, test">

</target>


........This does transform into html but with the following error message:

TestMath

java.lang.ClassNotFoundException: TestMath at java.net.URLClassLoader.findClass(URLClassLoader.j ava:375) at java.lang.ClassLoader.loadClass(ClassLoader.java:5 62) at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:442) at java.lang.ClassLoader.loadClass(ClassLoader.java:4 94) at java.lang.Class.forName1(Native Method) at java.lang.Class.forName(Class.java:180)

....The build is only successful because haltonfailure is set to no!

I know this is a big question, but any help would be very much greatly appreciated.

Danny Knights
ENGLAND.
Feb 28 '07 #3
Has anyone found an answer to this problem? I too am running into this issue.

Thanks,

Paul

Hi Danny Knights,
Did you got any solution for the below problem. because i am also facing the same problem. If you got solution please help me..

thanks
kishore
Apr 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tiago Miguel Silva | last post by:
I there. I´m almost desperate with a report that i´m doing! I am creating a report using the push method, being the data returned by a typed dataset. The report shows activities by week and...
1
by: John Baker | last post by:
Hi: I need some help writing code that will "print" a report using Cute FTP. Specifically, I need to set up a "Button" which, when clicked, will: a. Create an FTP "Print" file of the...
0
by: Crash | last post by:
Hello everyone, I need help creating an asp page to view a crystal report, which requires that that I change the database connection dynamically. I thought I had this problem licked in CR7 (the...
3
by: dalejasper | last post by:
I make a program using vb6, and link the database using adodc connection, I make also a report using the DataReport and DataEnvironment. When I print my report for the first time, It works very...
0
by: DhavalPatel1983 | last post by:
Hi, I need help in VB Datareport, my problem describe as below.... I have one Bank application project with all the information like Deposite,Clearness,Check,Cash,Creadit,ATM...
3
by: Amy Smith | last post by:
Hello there, I am having a small problem which been challenging me for few days and need help or advice. I am trying to calculate the day-shift for employees based on the time they started and...
2
by: vidhyapriya | last post by:
hi i m using crystal report in vb.net...In button click i m using another form to view crystal report viewer..whenever i click the button the pages r added...first time i click button the total...
4
by: Peter Herath | last post by:
I need to create an access report uisng VBA code. i want to be able to create a report name and save it and also create labels and text boxes in the report using the vba code and those fields should...
4
by: access baby | last post by:
i have a huge database based on date and time need to create different report we need to measure our work processes how many order received , order cancelled, completed and count of items completed...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.