Results 1 to 2 of 2
  1. #1
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Problems running junit tests from ant

    Hi,

    I am building ant makefiles for my projects and now I wanted to run all tests automatically, too.

    I defined the important properties in my build.xml file:
    <property name="src" location="src" />
    <property name="build" location="../out/ant/Library" />
    <property name="dist" location="../out/dist" />
    <property name="lib" location="../lib" />
    <property name="testsrc" location="test-src" />
    <property name="buildtest" location="../out/ant/Library-Test" />

    I defined some class-paths for my jobs:
    <path id="compile.class.path">
    <pathelement location="${lib}/de.kneitzel.lib-0.0.2.jar" />
    <pathelement location="${lib}/jdom.jar" />
    <pathelement location="${lib}/log4j.jar" />
    </path>

    <path id="testcompile.class.path">
    <path refid="compile.class.path" />
    <pathelement location="${lib}/junit-4.11.jar" />
    <pathelement location="${build}" />
    </path>

    <path id="junit.class.path">
    <path refid="testcompile.class.path" />
    <pathelement location="${lib}/hamcrest-core-1.3.jar" />
    <pathelement location="${buildtest}" />
    </path>

    And have jobs to compile the source:

    <target name="compile" depends="init"
    description="compile the source " >
    <javac srcdir="${src}" destdir="${build}" includeantruntime="false">
    <classpath refid="compile.class.path" />
    </javac>
    </target>

    <target name="compileTest" depends="dist">
    <!-- Compile the java code from ${testsrc} into ${build} -->
    <javac srcdir="${testsrc}" destdir="${buildtest}" includeantruntime="false">
    <classpath refid="testcompile.class.path" />
    </javac>
    </target>

    These work fine.

    And I have a task to run the tests:

    <target name="test" depends="compileTest">
    <junit>
    <classpath refid="junit.class.path" />
    <batchtest>
    <fileset dir="${testsrc}">
    <include name="**/*Tests*" />
    </fileset>
    </batchtest>
    <formatter type="brief" usefile="false"/>
    </junit>
    </target>

    And this is not running. I get class not found errors:

    [junit] Testcase: UseObjectEventSyncTest(tests.events.UseObjectEvent Tests):Caused an ERROR
    [junit] de.kneitzel.jadv.lib.events.JAdvEvent
    [junit] java.lang.NoClassDefFoundError: de.kneitzel.jadv.lib.events.JAdvEvent
    [junit] at tests.events.UseObjectEventTests.UseObjectEventSyn cTest(Unknown Source)
    [junit]
    [junit]
    [junit] Test tests.events.UseObjectEventTests FAILED

    The class JAdvEvent that the system is complaining about is inside the build directory (So it was compiled by the compile task). And while compiling the tests, the compile had to find that class, too.

    So I am wondering what is wrong right now. It seems that I am missing something but I do not see what that is.

    I added the complete build.xml file as attachement (renamed to build.txt) because I left out some tasks (which shouldn't be important to solve my problem).

    Maybe someone has an idea for me.

    With kind regards,

    Konrad
    Attached Files Attached Files

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: Problems running junit tests from ant

    Ok, stupid me:

    The pathelement can have 2 attributes: location to add a file and path to add a directory.
    I simply changed the entries that define a directory from location to path and the error seems to be gone.
    (e.g. <pathelement path="${buildtest}" />)

    Konrad

Similar Threads

  1. Question about my program and JUnit tests
    By pokadean in forum New To Java
    Replies: 6
    Last Post: 07-26-2013, 01:02 PM
  2. Have JUnit tests, need help developing methods
    By alpdog14 in forum New To Java
    Replies: 20
    Last Post: 03-24-2011, 08:27 AM
  3. Junit tests with ant
    By questioner in forum New To Java
    Replies: 3
    Last Post: 04-26-2010, 10:25 AM
  4. Remote Junit Tests
    By lord.ec in forum Eclipse
    Replies: 0
    Last Post: 12-09-2008, 08:15 AM
  5. Using ant to run JUnit tests
    By racerxadam in forum Advanced Java
    Replies: 0
    Last Post: 10-21-2008, 04:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •