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 6236643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:53:08+00:00 2026-05-24T10:53:08+00:00

I have JUnit tests on my project that run correctly with Eclipse. So, now

  • 0

I have JUnit tests on my project that run correctly with Eclipse.

So, now I try to integrate these tests with an ant task. To make that I make the following ant script :

<path id="classpath-test">
    <pathelement path="." />
    <pathelement path="${classes.home}" />
    <fileset dir="${lib.home}" includes="*.jar" />
    <fileset dir="${libtest.home}" includes="*.jar" />
</path>

    <target name="compile" ... > // compiles src code of the project

<target name="compile-tests" depends="compile">
    <javac  srcdir="${test.home}"
            destdir="${testclasses.home}" 
            target="1.5"
            source="1.5" 
            debug="true"
        >
        <classpath refid="classpath-test" />
    </javac>

    <copy todir="${testclasses.home}">
        <fileset dir="${test.home}">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>

<target name="unit-test" depends="compile-tests">
    <junit printsummary="false" fork="off" haltonfailure="true">
        <classpath refid="classpath-test" />

        <formatter type="brief" usefile="false" />

        <test name="com.test.MyTest" />

        <!--<batchtest todir="${reports.dir}" >
            <fileset dir="${testclasses.home}" >
                <exclude name="**/AllTests*"/>
                <include name="**/*Test.class" />
            </fileset>
        </batchtest>-->
    </junit>
</target>

The directory ${libtest.hom} contains junit-4.8.1.jar and hamcrest-core-1.1.jar.

When I launch the following command : ant unit-test, the execution of the MyTest fails with the following output :

unit-test:
[junit] Testsuite: com.test.MyTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]
[junit] Null Test:  Caused an ERROR
[junit] com.test.MyTest
[junit] java.lang.ClassNotFoundException: com.test.MyTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit]     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:247)
[junit]
[junit]

It’s very strange because com.test.MyTest is well in the classpath pointed for my task junit in ant script. Someone would have and idea to solve this problem ?

Thanks for your help.

Sylvain.

  • 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-24T10:53:08+00:00Added an answer on May 24, 2026 at 10:53 am

    The ${testclasses.home} directory is nowhere on a classpath for <junit> task.

    I think this is where class file for com.test.MyTest lives.

    Here is modified unit-test target:

    <target name="unit-test" depends="compile-tests">
        <junit printsummary="false" fork="off" haltonfailure="true">
            <classpath>
              <path refid="classpath-test"/>
              <fileset dir="${testclasses.home}"/>
            </classpath>
    
            <formatter type="brief" usefile="false" />
    
            <test name="com.test.MyTest" />
    
            <!--<batchtest todir="${reports.dir}" >
                <fileset dir="${testclasses.home}" >
                    <exclude name="**/AllTests*"/>
                    <include name="**/*Test.class" />
                </fileset>
            </batchtest>-->
        </junit>
    </target>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my Java Eclipse project that contains JUnit tests, I also have a package
I have a JUnit test that tests adding Strings to a Dictionary custom type.
I have an extremely odd problem in my JUnit tests that I just can't
In a maven project I have some junit tests where I need to refer
I have a Maven-managed project that uses Mockito mocking in its unit tests. I
I have a project in Java with JUnit tests in Scala. Each test class
I have many JUnit tests, which are all created by Netbeans' assistant (so nothing
I have written JUnit tests for my class, and would like it to tell
I wanted to choose the order to execute the JUnit tests. I have 4
We have a lot of integration tests written using JUnit 3 , though we're

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.