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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:24:25+00:00 2026-06-14T18:24:25+00:00

I have created an Ant target to compile my code. <target name=test depends=compile> <junit>

  • 0

I have created an Ant target to compile my code.

<target name="test" depends="compile">
    <junit>
        <classpath>
            <pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
        </classpath>
        <classpath>
            <pathelement path="${build}"/>
        </classpath>
        <test name="BinarySearchTest" />
    </junit>
</target>

<target name="compile">
    <mkdir dir="${build}"/>
    <javac
        srcdir="${basedir}\src;${basedir}\..\SwaCore\src;${basedir}\..\SwaShared\src;${basedir}\..\SwaDictionary\src;${basedir}\..\SwaSuggestion\src;${basedir}\..\SwaServerSharedCore\src;${basedir}\..\SwaPrediction\src;"
        destdir="${build}"
        debug="true"
        debuglevel="lines,vars,source">
        <classpath>
            <pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
            <pathelement path="${basedir}\..\SwaSuggestion\lib\ssce.jar"/>
            <pathelement path="C:\Java\javamail-1.4.1\mail.jar"/>
            <pathelement path="C:\Java\commons-net-2.0\commons-net-ftp-2.0.jar"/>
            <pathelement path="${basedir}\WebContent\WEB-INF\lib\gson-2.2.1.jar"/>
            <pathelement path="${tomcatLibs}\servlet-api.jar"/>
        </classpath>
    </javac>
</target>

The compile works fine, all my classes are in the folder pointed to by ${build}. I assume this ${build} will be the classpath for my JUnit test case.
I then have a test target that I want to run a JUnit test Called BinarySearchTest. When I run this I get the simple error

Test BinarySearchTest FAILED

I know my Unit test is ok because it tests nothing.

public class BinarySearchTest extends TestCase
{
    public void test()
    {       
    }
}

Even if I put the following in my test target I still get the same error

<test name="AtestThatDoesNotExistTest" />

result =

Test AtestThatDoesNotExistTest FAILED

I would have expected a classNotFound error so there is obviously something fundamentally wrong with my Ant XML

JUnit jar is being picked up ok because if it’s not in the classpath I will get the error

The <classpath> for <junit> must include junit.jar if not in Ant's own classpath

Update
I modified my target to include

        <formatter type="brief" usefile="false" />
        <test name="com.swaserver.junit.BinarySearchTest" />

test:
[junit] Testsuite: com.swaserver.junit.BinarySearchTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.878 sec
[junit] ------------- Standard Output ---------------
[junit] Initializing Binary search class
[junit] Binary search class initialized
[junit] ------------- ---------------- ---------------

BUILD SUCCESSFUL
Total time: 2 seconds

Now I can see that my test is actually run. However I get a class not found unless I specify the fully qualified class name for my unit test. Why would this be?

  • 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-06-14T18:24:26+00:00Added an answer on June 14, 2026 at 6:24 pm

    You may try

        <classpath>
            <pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
            <pathelement path="${build}"/>
        </classpath>
    

    instead of

        <classpath>
            <pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
        </classpath>
        <classpath>
            <pathelement path="${build}"/>
        </classpath>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ant task set up like so: <target name=unit-test description=unit tests depends=compile-tests>
I have got three selenium test classes and have created three ant targets for
I have following ant script to generate the jar file <project name=myProject basedir=. default=jar>
I have created an ant project which has some targets inside. One target is
I have build.xml for my project, but even this small piece of code <target
I have android test project that i've integrated into the Hudson. I have created
I am trying to get Junit work with Ant. I have come across questions
I have a NetBeans project that I'm trying to compile manually from command-line ant
I have created a Java application which has the following Apache Ant build file:
I have created a custom Ant task as per one of my previous posts

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.