I have the following JUnit test in eclipse:
package test;
import org.junit.Test;
public class SimpleJUnitTest
{
@Test
public void doTest() { System.out.println("Test did run"); }
}
And the following build.xml in the same folder:
<?xml version="1.0" encoding="UTF-8"?>
<project name="LoggerTest" default="JUnitTest" basedir=".">
<target name="JUnitTest">
<junit>
<classpath location="../../lib/junit.jar" />
<test name="test.SimpleJUnitTest" />
</junit>
<echo>boo</echo>
</target>
</project>
If I run the test class under "Run As..." and choose JUnit, it runs without error. If I run the build.xml under "Run As..." and choose Ant Build, I get the following output:
Buildfile: C:\Users\995868\workspace\JUnit1\tst\test\build.xml
JUnitTest:
[junit] Test test.SimpleJUnitTest FAILED
[echo] boo BUILD SUCCESSFUL Total time: 390 milliseconds
If I remove the classpath attribute under JUnit, I get a different error message about needing the junit jar on the classpath, so I think JUnit is getting invoked. I just don't understand what its error is here. I've tried putting static block code in the class to do a System.out.println()
when the class is loaded, and it does not appear, so there seems to be something I'm doing wrong in the configuration.
Can someone please tell me what's wrong here?
EDIT:
directory structure:
JUnit1
--bin
--test
--SimpleJUnitTest
--lib
--junit.jar
--scripts
--build.xml
--src
--tst
--test
--SimpleJUnitTest.java
I also copied build.xml to tst and ran it from the command line from that directory, same result.
I've copied junit.jar to %ant_home%\lib with no effect, though when I took the pathelement line out of the classpath I got the message "The for must include junit.jar if not in Ant's own classpath". I'm not sure where "Ant's own classpath" is specified. The classpath block with the new error message is this:
<classpath>
<pathelement location="c:/users/995868/apache-ant-1.9.4/lib" />
<pathelement location="../bin" />
</classpath>
I'm not using hamcrest features anywhere, so I haven't looked it up and put it in. I was trying to make a simple example, and the documentation for junit under ant (at least) does not mention that hamcrest is necessary.