0
votes

I'm trying to execute a few junit test suits with ant.

Here's my folder structure

  • bin
  • lib
  • src
  • test
  • build.xml

First of all I compile all files in source location, later on java files in test folder.

Whole structure of test folder (compiled .class files) are saved in bin folder which looks like this inside.

bin-test-alltests | -suites - SetupSuite.class - StartSuite.class

in allTests folder are tests that are used in suites in suites folder

I'm trying to start those suites but constantly I've got an error:

ant junit java.lang.noclassdeffounderror wrong name

I'm pretty sure that's something wrong with the class path but I don't know what. I've tried to changed

<test name="SetupSuite"/> to

<test name="SetupSuite.class"/>

and I get another error:

java.lang.ClassNotFoundException: SetupSuite.class

Here's my build.xml file

<project name="MyTest" basedir=".">

    <!--Common properties -->
    <property name="src.dirname" value="src" />
    <property name="test.dirname" value="test" />
    <property name="lib.dirname" value="lib" />
    <property name="bin.dirname" value="bin" />
    <property name="src.encoding" value="utf8" />
    <property name="src.version" value="1.7" />
    <property environment="env" />

    <!-- Paths for MyTest -->
    <property name="MyTest.dir" value="${basedir}" />
    <property name="MyTest.src.dir" value="${MyTest.dir}\${src.dirname}" />
    <property name="MyTest.test.dir" value="${MyTest.dir}\${test.dirname}" />
    <property name="MyTest.dest.dir" value="${MyTest.dir}\${bin.dirname}" />
    <property name="MyTest.lib.dir" value="${MyTest.dir}\${lib.dirname}" />

    <path id="classpath">
        <pathelement location="${MyTest.lib.dir}\junit.jar" />
        <pathelement location="${MyTest.test.dir}\test\suites\" />
    </path>

    <target name="compile-MyTest-src" >
        <myjavac srcdir="${MyTest.src.dir}" destdir="${MyTest.dest.dir}" classpath="{MyTest.lib.dir}\junit.jar"/>
    </target>

    <target name="compile-MyTest-test" depends="compile-MyTest-src">
        <path id='libs'>
            <fileset dir= "${MyTest.lib.dir}\" includes="**/*.jar"/>
        </path>
    <myjavac srcdir="${MyTest.test.dir}\" destdir="${MyTest.dest.dir}" classpathref = 'libs'/>
    </target>

    <target name="execute-tests" depends="compile-MyTest-src,compile-MyTest-test">
        <junit printsummary="yes" haltonfailure="no" showoutput="yes">
        <formatter type = "brief" usefile = "false" />
        <classpath refid="classpath" />
            <test name="SetupSuite"/>
        </junit>
    </target>   

   <!-- General compiler settings -->
    <presetdef name="myjavac">
        <javac classpathref="classpath" debug="on" includeantruntime="false" encoding="${src.encoding}" source="${src.version}" target="${src.version}" />
    </presetdef>

</project>
2
Please show us the problematic test suite.Markus

2 Answers

0
votes

Solved. I had to add hamcrest-core-1.3.jar file to classpath

0
votes

You need to set test name to full name of your SetupSuite:

<test name="alltests.suites.SetupSuite"/>