Running Android JUnit tests with Ant: ClassNotFoundException: org.junit.Test

I am attempting to get my JUnit tests for an Android application running using Ant. While using Eclipse, it is no problem, all is compiled and can be run with no problem.

At the moment I am receiving a ClassNotFoundException to org.junit.Test.

I am running the following commands

ant clean debug - success
ant uninstall - success
ant installt - success
ant test - failure

error log:

test:
     [echo] Running tests ...
     [exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
     [exec] INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: org.junit.Test
     [exec] INSTRUMENTATION_CODE: 0

I suppose, it misses junit.jar file. I added it into my ANT_HOME/lib directory, but it didn't have any effect.

I also tried to add it in the classpath of my test project and marked it to be exported. Also in that case the result remains unchanged.

I am sure that I am missing something very easy here. If further configuration details are needed, I'll be glad to provide them. I appreciate your help.
AndroidAndroidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
What version of junit.jar did you place into the ANT_HOME\lib directory?

Also, can you post the contents of your build.xml file?
0
AndroidAndroidAuthor Commented:
Thank you for your reply, mccarl! I inserted JUnit 4.11 .jar.

My build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="FSTest" default="help">
    <property file="local.properties" />
    <property file="ant.properties" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />
    </condition>
    <loadproperties srcFile="project.properties" />
    <fail
            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
            unless="sdk.dir"
    />
    <import file="custom_rules.xml" optional="true" />
    <import file="${sdk.dir}/tools/ant/build.xml" />  
</project>
0
girionisCommented:
Your build file includes other files, so it's difficult to tell what's going on. Why don't you export the ant file (via the Export... choice of Eclipse) and modify it according to your needs?
0
AndroidAndroidAuthor Commented:
Thank you for the suggestion, girionis. Sadly, using the generated build.xml could not help me further. The error remained.
However, after adding the following lines to my build.xml, I got rid of the error message:

 <path id="junit.class.path">
    <pathelement location="lib/junit.jar" />
    <pathelement location="${build.dir}" />
  </path>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndroidAndroidAuthor Commented:
With this solution, I can run the tests with ant.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.