This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Problem setting Ant junit task" Watch "Problem setting Ant junit task" New topic
Author

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>
</target>

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="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>
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
Greenhorn

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
Irene
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
Greenhorn

Joined: Sep 18, 2003
Posts: 7
Hi,
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
vijay
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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]
 
Don't get me started about those stupid light bulbs.
 
subject: Problem setting Ant junit task
 
Similar Threads
Problem with Eclipse and the servicegen task of weblogic
Ant FPT missing class ...
ant 1.6 and junit task
ANT could not find class for <junit>
JUNIT testing working but strangly or biasing with dos window