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

Problem setting Ant junit task

Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
Hi, All:
I am new to JUnit, but not so much to Ant. I got JUnit 3.8.1 today and ran succesfully a few tests, both with GUI or TextUI. However, I encountered a problem integrating Ant to Junit.
According to Ant's documentation, I put junit.jar into ANT_HOME/lib where ant.jar and optional.jar are. The following are what I have got when I started to run:
<target name="runtest">
<junit><test name="FirstHinTest"/></junit>

It first complains about not being able to creat task <junit>. I thought as long as optional.jar and junit.jar are in the ANT_HOME/lib, it should just recognize the junit as one of the optional Ant tasks and run it (that's the impression I got from documentation). Anyways, I put in
<taskdef name="junit" classname=""/>
to define the tast and it showed me another error:
java.lang.NoClassDefFoundError: org/apache/tools/ant/ProjectComponent
Since this class is in ant.jar, so I put ANT_HOME/lib/ant.jar in the CLASSPATH. Then it gives me this error:
java.lang.VerifyError: (class: org/apache/tools/ant/taskdefs/optional/ide/VAJExp
ort, method: execute signature: ()V) Incompatible object argument for function call
This really get me stuck and puzzled. This looks like a mismatch in class definiations. I must be missing something seriously.
Any help is appreciated.

Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
Irene Fernandez

Joined: Jan 26, 1999
Posts: 15
I recently setup Ant using JUnit. [1]My first solution was to put the junit.jar in the ANT_HOME/lib directory. I do have a system environment variable set for ANT_HOME = C:\jakarta-ant-1.5 and no classpath. This worked. Have you checked your definition of ANT_HOME? [2]My second solution was to leave the junit.jar in the JUNIT_HOME. I have defined a classpath which includes: C:\Junit3.8.1\junit.jar and I have ANT_HOME = C:\jakarta-ant-1.5
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
You are right. I have solved this problem a few days ago. The problem was my PC has been upgraded and I forgot to put int ANT_HOME. oops.
Thanks anyways.
vijay peyyala

Joined: Sep 18, 2003
Posts: 7
When I run my ant test for a class from GUI through my IDE I get an "assertion failed" error when it is supposed to. But at the same instance if I run "ant junit" it shows me successful for the build. Please solve my problem.
Thanks n regards
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Vijay, please don't crosspost a question into several threads.
Discussion related to Vijay's question should be continued in the other thread.
[ December 30, 2003: Message edited by: Lasse Koskela ]

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Problem setting Ant junit task
It's not a secret anymore!