Im trying to run some JUnit tests using a Ant script. I can run them in Eclipse, but I am having problems when doing it using Ant.
I have a simple class, called Calculator that does some calculations, this is my class:
Calculator.java
package CalculatorSrc;
public class Calculator {
public double add(double n1, double n2){
return n1+n2;
}
//...
}
And then I have another class to test my methods like:
TestCalculator.java
package CalculatorTests;
import static org.junit.Assert.*;
import org.junit.*;
import CalculatorSrc.Calculator;
public class TestCalculator {
@Test
public void testAdd(){
Calculator calc = new Calculator();
double result = calc.add(10, 50);
assertEquals(60, result, 0);
}
//...
}
My project dir is this:
Finally, my Ant script to run JUnit tests is this:
<property name="build.classes.dir" location="build/classes"/>
<property name="class.src.dir" location="src/CalculatorSrc"/>
<property name="tests.src.dir" location="src/CalculatorTests"/>
<property name="reports.dir" location="reports"/>
<path id="classpath.base" />
<path id="test.classpath">
<pathelement location="${class.src.dir}"/>
<pathelement location="${tests.src.dir}"/>
<pathelement location="${build.classes.dir}"/>
<pathelement location="tools/JUnit/junit-4.12.jar"/>
<pathelement location="tools/JUnit/hamcrest-core-1.3.jar"/>
<pathelement location="tools/JUnit/ant-junit-1.9.4.jar"/>
</path>
<target name="build">
<antcall target="test-compile"/>
<antcall target="test"/>
</target>
<target name="test-compile">
<javac includeantruntime="false" srcdir="${class.src.dir}" destdir="${build.classes.dir}" debug="true">
<classpath refid="classpath.base"/>
</javac>
<javac includeantruntime="false" srcdir="${tests.src.dir}" destdir="${build.classes.dir}" debug="true">
<classpath refid="test.classpath"/>
</javac>
</target>
<target name="test">
<junit haltonfailure="no" failureproperty="failed">
<classpath>
<path refid="test.classpath"/>
<pathelement location="${build.classes.dir}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${reports.dir}">
<fileset dir="${tests.src.dir}" includes="**/*Test*.java"/>
</batchtest>
</junit>
<fail message="TEST FAILURE" if="failed"/>
</target>
When I run the Ant script using Jenkis my build fails... If I go check the xml file created I see the error ClassNotFoundException...
What am I doing wrong?
EDIT:
Here are some prints of the output of Jenkins when I build my project:
As you can see in the next screenshot jenkins can find my build.xml...
And here is the error that I have:
The line 57 of my build.xml is <antcall target="test"/>
and the line 121 is <fail message="TEST FAILURE" if="failed"/>
.