You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Taemin Cim <qw...@hotmail.com> on 2006/02/14 02:54:35 UTC

Broken Junit targets

Hi All!

I've broken my junit task in Ant...I got an error in a side project where it 
couldnt import TestCase, so I copied the junit.jar into the lib dir for that 
project, and got "could not create task of type junit" when I ran Ant.
So I realized Ant has its own ant-junit.jar, so I deleted the junit.jar 
which I had moved, but now ALL my projects are broken for running tests from 
Ant, even though I put things back to the way they were before.  I rebooted, 
etc.  Why would this side project effect all junit tasks?

In my build file I have the junit jar included only for tests.
  <path id="compile.classpath">
    <pathelement path ="lib/hibernate3.jar"/>
    <pathelement path ="lib/commons-lang-1.0.1.jar"/>
    <pathelement path ="lib/commons-logging-1.0.4.jar"/>
  </path>

  <path id="test.classpath"><path refid="compile.classpath"/><pathelement 
location="${junit.jar}"/>
    <pathelement location="${build.dir}/classes"/>
    <pathelement location="${build.dir}/test"/>
  </path>

The complie works, but the tests fail:

build.xml:154: Could not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and install needed JAR 
files,
or fix the build file:
- You have misspelt 'junit'.  				<--- NOT THE PROBLEM
	Fix: check your spelling.
- The task needs an external JAR file to execute
	and this is not found in the right place in the classpath <--- NOT THE 
PROBLEM
	Fix: check the documentation for dependencies.			Ant's Junit class worked 
fine before
	Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries <--- 
NOT THE PROBLEM
	implementing the functionality were not found at the time you	   I didn't 
build ant myself
	yourself built your installation for Ant from the Ant sources.
	Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the   
<--- ant-junit.jar is there
	task and make sure it contains more than merely a META-INF/MANIFEST.MF.
	If all it contains is the manifest, then rebuild Ant with the needed     
<--- checked the jar, it&#347; good
	libraries present in ${ant.homw}/lib/optional/ , or alternatively,
	download a pre-built release version from apache.org
- The build file was written for a later version of Ant				 <--- my build 
file didn't change
	Fix: upgrade to at least the latest release version of Ant		      from when 
junit tagets ran
- The task is not an Ant core or optional task and needs to be declared 
using <taskdef>  <--- NOT THE PROBLEM
- You are attempting to use a task defined using		<--- NOT THE PROBLEM
	<presetdef> or <macrodef> but have spelt wrong or not
	defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented in
	ANT_HOME/lib, the files must be in the same directory or on the classpath.
Please netither file bug reports on this problem, nor email the
	Ant mailing lists, until all of these causes have been explored,
	as this is not an Ant bug.

Here is the test target:

  <target name="test-batch" depends="test-compile">
    <junit printsummary="withOutAndErr" haltonfailure="false">   <-- line 
154
      <classpath refid="test.classpath"/>
      <formatter type="brief" usefile="true"/>
      <formatter type="xml"/>
      <batchtest todir="${test.data.dir}">
        <fileset dir="${test.dir}" includes="**/*Test.class"/>
      </batchtest>
    </junit>
    <junitreport todir="${test.data.dir}">
      <fileset dir="${test.data.dir}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="${test.reports.dir}"/>
    </junitreport>
  </target>

in properties.xml

  <property name="junit.dir"   location="${ant.home}/lib"/>

    <property name="junit.subdir"      value=""/>

    <property name="junit.jar" 
location="${junit.dir}/${junit.subdir}/junit.jar"/>

    I changed junit.jar to ant-junit.jar:

    <property name="junit.jar" location="${junit.dir}/ant-junit.jar"/>

Still got the error.
I have two junit.jar files:

in junit3.8.1 which is used for the JUNIT_HOME variable

and

in apache-ant-1.6.5/lib/ant-junit.jar

could there be a conflict between the junit.jar in the JUNIT_HOME variable 
and the ant/lib/ant-junit.jar when running the junit task from ant?

/home/timmy/apache-ant-1.6.5/lib/ant-junit.jar and 
/home/timmy/junit3.8.1/lib/junit.jar

I found this post on the mailing lists after googling:

> > But I have notified that I have two junit.jars in the above
> > classpath. One in the ANT/lib dir (so that Ant knows of the junit
> > task) and one in the project classpath (WEB-INF/lib) . Could that
> > cause any problems ?
>
>No, at least not as long as both are the same version.

In the ant-junit.jar manifest I found:

Ant-Version: Apache Ant 1.6.5
MY version : apache-ant-1.6.5

So, as the poster said, shouldn't be a problem.  Keep in mind, before this 
fiasco, I had the tests running from this side project fine.  I still don't 
know why all of a sudden the build couldn't find TestCase and made me copy 
the junit.jar to the subprojects lib in the first place, consequently 
messing up all my projects testing ability!
Keep in mind, I've been using junit tasks on this particular box running 
Fedora Core 3 for over a year, with no changes to the jars.  The sub project 
is a Hibernate learning project.  I can't get Hibernate configured correctly 
to talk to MySQL, so I made a sub project to test the connection.  This 
seems like too much info, so I'm sorry for overdoing it.

Thanks for your time

Taemin.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Broken Junit targets

Posted by Stephen McConnell <mc...@dpml.net>.
 

> Same error.

Have you invoked ant with the -v option?
This will give you sufficient information to establish where ant is loading
things from (and info about any references that are dropped because they
don't exist.

/Steve.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Broken Junit targets

Posted by Taemin Cim <qw...@hotmail.com>.
Hi,

I'm still getting the same "Could not create task or type of type: junit" 
error.
I created a separate ant-junit pathelement in the properties.xml file:

    <property name="junit.jar"
    location="${junit.dir}/junit.jar"/>

  <property name="ant-junit.jar"
    location="${ant.home}/lib/ant-junit.jar"/>

I then reference both in the build.xml file:

  <path id="test.classpath">
    <path refid="compile.classpath"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${ant-junit.jar}"/>
    <pathelement location="${build.dir}/classes"/>
    <pathelement location="${build.dir}/test"/>
  </path>

Same error.

I changed the <property name="junit.fork" value="true"/> to value="false"

Same error.

So I tried to implement the setup-path and test targets as Steve suggested:

  <!-- Suggested by Stephen McConnell -->
  <target name="setup-path" depends="init">
    <path id="project.main.path">
      <pathelement location="${ant.jar}"/>
      <pathelement location="${build.dir}/classes"/>
    </path>
    <path id="project.test.path">
      <path refid="project.main.path"/>
      <pathelement location="${ant-junit.jar}"/>
      <pathelement location="${junit.jar}"/>
    </path>
  </target>

  <!--  refid changed from test.classpath to setup-path -->
  <target name="test" depends="test-compile">
    <junit printsummary="true"
           errorProperty="test.failed"
           failureProperty="test.failed"
           fork="${junit.fork}">
      <classpath>
        <path refid="setup-path"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
      <formatter type="brief" usefile="true"/>
      <formatter type="xml"/>
      <test name="${testcase}" todir="${test.data.dir}" if="testcase"/>
      <batchtest todir="${test.data.dir}" unless="testcase">
        <fileset dir="${test.dir}" includes="**/*Test.class"/>
      </batchtest>
    </junit>

Same error.

I still don't understand how, without changing any environment path settings 
or anything elese, copying the junit.jar to a side projects lib directory 
has broken the test target for all other projects on my system.
There must be some kind of classloader memory that survives reboots that I 
offended with the seemingly innocuos copy file which I was then unable to 
erase by deleting the offending jar.


>From: "Stephen McConnell" <mc...@dpml.net>
>Reply-To: "Ant Users List" <us...@ant.apache.org>
>To: "'Ant Users List'" <us...@ant.apache.org>
>Subject: RE: Broken Junit targets
>Date: Tue, 14 Feb 2006 15:30:35 +1030
>
>
>
> > -----Original Message-----
> > From: Taemin Cim [mailto:qwertypoi75@hotmail.com]
> > Sent: Tuesday, 14 February 2006 1:46 PM
> > To: user@ant.apache.org
> > Subject: RE: Broken Junit targets
> >
> > Hi again,
> >
> > >The ant-junit.jar is dependent on the JUnit jar file.
> > >You can add JUnit to ${ant.home}/lib, or your ${user.home}/.ant/lib
> > >directory.
> > >
> > >/Steve.
> > >
> >
> > I have the junit.jar on the test.classpath in the build file.
> >  How else should I associate the junit,jar witht eh
> > ant-junit.jar?   Where should I "add JUnit to ${ant.home}/lib,
> > or your ${user.home}/.ant/lib"  If the junit,jar in on the
> > test classpath, and ant knows it has ant-junit.jar, what more
> > should I do (and how did I break this connection after a year or
> > testing?)
>
>There are lots of ways you can play around with classpath composition in
>ant.  The important thing to note is that ant-junit requires junit jar to 
>be
>in the same or higher classloader.  If the junit jar is present in either
>${ant.home}/lib or ${user.home}/.ant/lib then it should be included in the
>same classloader that contains ant-junit. This is visible in that when you
>compile classes referencing junit classes the compilation succeeds.
>However, your forking during the execution of the testcase and (I'm 
>guessing
>here) you probably need to provide the complete classloader definition.
>
> >   <target name="test-batch" depends="test-compile">
> >     <junit printsummary="withOutAndErr" haltonfailure="false">
> >       <classpath refid="test.classpath"/>
>
>Here is an example of the setup of a two path objects that are subsequently
>used in a forked junit test.  Perhaps it will help in resolving your issue.
>
>   <target name="setup-path" depends="init">
>     <path id="project.main.path">
>       <pathelement location="${ENV.ANT_HOME}/lib/ant.jar"/>
>       <pathelement location="${target.classes.dir}"/>
>     </path>
>     <path id="project.test.path">
>       <path refid="project.main.path"/>
>       <pathelement location="${ENV.ANT_HOME}/lib/ant-junit.jar"/>
>       <pathelement
>location="${dpml.local.cache}/junit/jars/${junit.filename}"/>
>     </path>
>   </target>
>
>   <target name="test" depends="build-tests" if="src.test.available">
>     <junit fork="true" dir="${basedir}"
>            printsummary="yes"
>            showoutput="true"
>            haltonfailure="yes" failureproperty="junit.failure"
>            haltonerror="yes" errorproperty="junit.error">
>       <classpath>
>         <path refid="project.test.path"/>
>         <pathelement location="${target.test-classes.dir}"/>
>       </classpath>
>       <formatter type="plain"/>
>       <formatter type="xml"/>
>       <batchtest fork="yes" todir="${target.test-reports.dir}">
>         <fileset dir="${target.build.test.dir}">
>           <include name="**/*TestCase.java"/>
>           <exclude name="**/Abstract*.java"/>
>         </fileset>
>       </batchtest>
>     </junit>
>   </target>
>
>Cheers, Steve.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Broken Junit targets

Posted by Stephen McConnell <mc...@dpml.net>.
 

> -----Original Message-----
> From: Taemin Cim [mailto:qwertypoi75@hotmail.com] 
> Sent: Tuesday, 14 February 2006 1:46 PM
> To: user@ant.apache.org
> Subject: RE: Broken Junit targets
> 
> Hi again,
> 
> >The ant-junit.jar is dependent on the JUnit jar file.
> >You can add JUnit to ${ant.home}/lib, or your ${user.home}/.ant/lib 
> >directory.
> >
> >/Steve.
> >
> 
> I have the junit.jar on the test.classpath in the build file. 
>  How else should I associate the junit,jar witht eh 
> ant-junit.jar?   Where should I "add JUnit to ${ant.home}/lib, 
> or your ${user.home}/.ant/lib"  If the junit,jar in on the 
> test classpath, and ant knows it has ant-junit.jar, what more 
> should I do (and how did I break this connection after a year or
> testing?)

There are lots of ways you can play around with classpath composition in
ant.  The important thing to note is that ant-junit requires junit jar to be
in the same or higher classloader.  If the junit jar is present in either
${ant.home}/lib or ${user.home}/.ant/lib then it should be included in the
same classloader that contains ant-junit. This is visible in that when you
compile classes referencing junit classes the compilation succeeds.
However, your forking during the execution of the testcase and (I'm guessing
here) you probably need to provide the complete classloader definition.

>   <target name="test-batch" depends="test-compile">
>     <junit printsummary="withOutAndErr" haltonfailure="false">
>       <classpath refid="test.classpath"/>

Here is an example of the setup of a two path objects that are subsequently
used in a forked junit test.  Perhaps it will help in resolving your issue.

  <target name="setup-path" depends="init">
    <path id="project.main.path">
      <pathelement location="${ENV.ANT_HOME}/lib/ant.jar"/>
      <pathelement location="${target.classes.dir}"/>
    </path>
    <path id="project.test.path">
      <path refid="project.main.path"/>
      <pathelement location="${ENV.ANT_HOME}/lib/ant-junit.jar"/>
      <pathelement
location="${dpml.local.cache}/junit/jars/${junit.filename}"/>
    </path>
  </target>

  <target name="test" depends="build-tests" if="src.test.available">
    <junit fork="true" dir="${basedir}"
           printsummary="yes"
           showoutput="true"
           haltonfailure="yes" failureproperty="junit.failure"
           haltonerror="yes" errorproperty="junit.error">
      <classpath>
        <path refid="project.test.path"/>
        <pathelement location="${target.test-classes.dir}"/>
      </classpath>
      <formatter type="plain"/>
      <formatter type="xml"/>
      <batchtest fork="yes" todir="${target.test-reports.dir}">
        <fileset dir="${target.build.test.dir}">
          <include name="**/*TestCase.java"/>
          <exclude name="**/Abstract*.java"/>
        </fileset>
      </batchtest>
    </junit>
  </target>

Cheers, Steve.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Broken Junit targets

Posted by Taemin Cim <qw...@hotmail.com>.
Hi again,

>The ant-junit.jar is dependent on the JUnit jar file.
>You can add JUnit to ${ant.home}/lib, or your ${user.home}/.ant/lib
>directory.
>
>/Steve.
>

I have the junit.jar on the test.classpath in the build file.  How else 
should I associate the junit,jar witht eh ant-junit.jar?  Where should I 
"add JUnit to ${ant.home}/lib, or your ${user.home}/.ant/lib"  If the 
junit,jar in on the test classpath, and ant knows it has ant-junit.jar, what 
more should I do (and how did I break this connection after a year or 
testing?)

I have a bashrc script to set environment variables:

export ANT_HOME=/home/timmy/apache-ant-1.6.5
export JUNIT_HOME=/home/timmy/junit3.8.1

I have a properties.xml to set ant variables:

  <!-- Load Environment Variables  -->
  <property name="ant.home" value="${env.ANT_HOME}" />
  <property name="junit.home" value="${env.JUNIT_HOME}" />

  <!-- library directory mappings -->
  <property name="junit.dir"   location="${junit.home}"/>

  <!-- JAR file mappings -->
  <property name="junit.jar" location="${junit.dir}/junit.jar"/>

In my Ant build.xml file I have:
...
  <property name="junit.fork" value="true"/>
  ...
  <path id="test.classpath">
    <path refid="compile.classpath"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${build.dir}/classes"/>
    <pathelement location="${build.dir}/test"/>
  </path>
  ...
  <target name="test-batch" depends="test-compile">
    <junit printsummary="withOutAndErr" haltonfailure="false">
      <classpath refid="test.classpath"/>
  ...



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Broken Junit targets

Posted by Stephen McConnell <mc...@dpml.net>.
 

> -----Original Message-----
> From: Taemin Cim [mailto:qwertypoi75@hotmail.com] 
> Sent: Tuesday, 14 February 2006 12:25 PM
> To: user@ant.apache.org
> Subject: Broken Junit targets
> 
> Hi All!
> 
> I've broken my junit task in Ant...I got an error in a side 
> project where it couldnt import TestCase, so I copied the 
> junit.jar into the lib dir for that project, and got "could 
> not create task of type junit" when I ran Ant.
> So I realized Ant has its own ant-junit.jar, so I deleted the 
> junit.jar which I had moved ... 

The ant-junit.jar is dependent on the JUnit jar file.  
You can add JUnit to ${ant.home}/lib, or your ${user.home}/.ant/lib
directory.

/Steve.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org