Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:32:34+00:00 2026-05-28T07:32:34+00:00

I am trying to get Junit work with Ant. I have come across questions

  • 0

I am trying to get Junit work with Ant. I have come across questions on the topic. I guess there is some small error somewhere but I can’t figure it out. Here is my Build file:

        <?xml version="1.0" encoding="UTF-8"?>
    <project name="IvleFileSync" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
      <!-- set global properties for this build -->
      <property name="src" location="src"/>
      <property name="build" location="build"/>
      <property name="dist"  location="dist"/>
        <!-- Variables used for JUnit testing -->
        <property name="test.dir" location="test" />
        <property name="test.report.dir" location="test-reports" />
     <path id="junit-classpath">
    <fileset dir="${test.dir}">
        <include name = "*" />
    </fileset>
     </path>

    <path id="files-classpath">
    <fileset dir="/usr/lib" >
        <include name="*.jar"/>
    </fileset>
    </path> 

      <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
    <mkdir dir="${test.report.dir}" />
      </target>

      <target name="compile" depends="init" description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
     <javac srcdir="${src}" destdir="${build}"> 
           <classpath>
        <path refid="files-classpath" />
    </classpath> 
    </javac>

       </target>

      <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/IvleFileSync-${DSTAMP}.jar" basedir="${build}"/>
      </target>

    <target name="compile-test" depends="compile" description="compile the tests " >
       <!-- Compile the java code from ${src} into ${build} -->
       <javac srcdir="${test.dir}" destdir="${build}"> 
         <classpath>
          <path refid="files-classpath" />
       </classpath> 
       </javac>

    </target>

    <target name="test" depends="compile-test" description="Execute Unit Tests" >
      <junit printsummary="yes" fork="yes" haltonfailure="yes" showoutput="false">
       <classpath >
    <path refid="files-classpath" />
    <path refid= "junit-classpath" />
       </classpath>
    <batchtest fork="yes" todir="${test.report.dir}/"> 
            <formatter type="xml"/> 
            <fileset dir="${test.dir}"> 
                <include name="*Test*.java"/> 
            </fileset> 
    </batchtest> 
      </junit>
    </target>

      <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${test.report.dir}" />
    <delete dir="${dist}"/>
      </target>
    </project>

And I have test files in /test directory as well as i have put the jars in ANT_HOME/lib

That does not work and I get this error when I dig up the test-results/….xml

<error message="NewEmptyJUnitTest"     type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: NewEmptyJUnitTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)

Thanks for helping me out…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:32:35+00:00Added an answer on May 28, 2026 at 7:32 am

    The classpath for the junit task does not include the output of the compile-test target. Use something like the following for the JUnit classpath:

    <classpath>
      <pathelement path="${build}"/>
      <path refid="files-classpath" />
      <path refid="junit-classpath" />
    </classpath>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to run a junit test I get the following error - java.lang.ClassCastException:
When trying to start my JUnit-Test out of Eclipse, I get a ClassNotFoundException. When
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
I have a Spring/JPA/Hibernate application and am trying to get it to pass my
I am trying to run JUnit test with a 1.5 JRE, but get the
Hey guys I've been trying all day to get an ant file to automatically
I'm trying to get JUnit 4 tests to properly run in Eclipse Indigo SR1,
I recently purchased a mac and am trying to get junit tests working on
i am trying to get a coverage report for my android junit test project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.