File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Junit with ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Junit with ant" Watch "Junit with ant" New topic

Junit with ant

anuja Edathu
Ranch Hand

Joined: Sep 09, 2005
Posts: 84
Hi ,
i have written one test case and i am able to run it successfully from eclipse
when i run it as Junit test. But when im trying to run the same class with ant with a test target

it fails . Can any one suggest what can i do about this .
Thanks and regards
Anuja K
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I think you'll need to tell us a bit more about your IDE settings and your test - what it does and which bit is failing when called from Ant.

In my experience, if a test passes in the IDE but fails from Ant, it's commonly due to using different classpaths or different starting directories, but it can be other things, too.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

I'm going to move this to our Ant forum where you can get more help on Ant classpaths.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Matt Harrah
Ranch Hand

Joined: Aug 05, 2006
Posts: 54
Assuming you're using Eclipse---

Eclipse puts JUnit in the classpath for you for free. Ant does not -- see Ant's documentation about library dependancies and optional tasks (of which the junit task is one).

The short answer solution is probably to put junit.jar in ANT_HOME/lib.
damien malone
Ranch Hand

Joined: May 06, 2003
Posts: 35
chances are that ant isnt finding the class you are running,

try this in the target

<junit printsummary="yes" fork="yes" haltonfailure="yes" showoutput="yes">
<classpath refid="compile.classpath"/>
<formatter type="xml"/>
<test name="name of your class" todir="junitreports"/>

Create the folder junitreports just off of where you run your tests

this will send the ant output to a file with a bit more detail, I would expect you will see a class not found exception or something similar in there
I agree. Here's the link:
subject: Junit with ant
jQuery in Action, 3rd edition