Hello,
I am relatively new to JUnit. I am using Eclipse and want to make my JUnit test a part of the build, as in when I run the build.xml file my JUnit tests are run as well and I get an html output with passed/failed results.
I have a project in Eclipse containing a singel source folder with a singel java class, I also have a singel test folder containing a singel JUnit test class.
The java class looks like this:
public class X {
int x;
int y;
int z;
public int met(int en, int to){
x = en;
y = to;
if (en > 3) {
z = x + y;
y += x;
if(2*z == y){
x = 2;
}
}
return x;
}
}
and the JUnit class looks like this:
import static org.junit.Assert.*;
import org.junit.Test;
public class XTest {
@Test
public void testMet() {
assertEquals(5, new X().met(5,-4));
assertEquals(2, new X().met(4,-4));
}
}
I have allready made Eclipse running the JUnit test (and got the green bar), si in my IDE it is all working fine.
But when I have included some taregets in my build.xml file I get build errors.
My build.xml file looks like this:
simple example build file
The build errors I get is:
Buildfile: C:\Documents and Settings\mfugleru\workspace\Modulis\build.xml
JUNIT:
init:
compile:
dist:
JUNIT:
init:
JUNIT:
JUNIT:
init:
compile:
JUNIT:
init:
compile:
jar:
[jar] Warning: skipping jar archive C:\Documents and Settings\mfugleru\workspace\Modulis\build\lib\${app.name}.jar because no files were included.
JUNIT:
init:
compile:
jar:
[jar] Warning: skipping jar archive C:\Documents and Settings\mfugleru\workspace\Modulis\build\lib\${app.name}.jar because no files were included.
compiletests:
[javac] Compiling 1 source file to C:\Documents and Settings\mfugleru\workspace\Modulis\build\testcases
[javac] C:\Documents and Settings\mfugleru\workspace\Modulis\test\XTest.java:9: cannot find symbol
[javac] symbol : class X
[javac] location: class XTest
[javac] assertEquals(5, new X().met(5,-4));
[javac] ^
[javac] C:\Documents and Settings\mfugleru\workspace\Modulis\test\XTest.java:10: cannot find symbol
[javac] symbol : class X
[javac] location: class XTest
[javac] assertEquals(2, new X().met(4,-4));
[javac] ^
[javac] 2 errors
BUILD FAILED
C:\Documents and Settings\mfugleru\workspace\Modulis\build.xml:42: Compile failed; see the compiler error output for details.
Total time: 812 milliseconds
I hope someone can help me with solving this, so I can make my JUnit tests a part of my build.
Thank you
Magnus J