Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Junit with ant

 
anuja Edathu
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to our Ant forum where you can get more help on Ant classpaths.
 
Matt Harrah
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>
</junit>

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic