I have created an Ant target to compile my code.
<target name="test" depends="compile">
<junit>
<classpath>
<pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
</classpath>
<classpath>
<pathelement path="${build}"/>
</classpath>
<test name="BinarySearchTest" />
</junit>
</target>
<target name="compile">
<mkdir dir="${build}"/>
<javac
srcdir="${basedir}\src;${basedir}\..\SwaCore\src;${basedir}\..\SwaShared\src;${basedir}\..\SwaDictionary\src;${basedir}\..\SwaSuggestion\src;${basedir}\..\SwaServerSharedCore\src;${basedir}\..\SwaPrediction\src;"
destdir="${build}"
debug="true"
debuglevel="lines,vars,source">
<classpath>
<pathelement path="${basedir}\..\SwaCore\lib\junit.jar"/>
<pathelement path="${basedir}\..\SwaSuggestion\lib\ssce.jar"/>
<pathelement path="C:\Java\javamail-1.4.1\mail.jar"/>
<pathelement path="C:\Java\commons-net-2.0\commons-net-ftp-2.0.jar"/>
<pathelement path="${basedir}\WebContent\WEB-INF\lib\gson-2.2.1.jar"/>
<pathelement path="${tomcatLibs}\servlet-api.jar"/>
</classpath>
</javac>
</target>
The compile works fine, all my classes are in the folder pointed to by ${build}. I assume this ${build} will be the classpath for my JUnit test case. I then have a test target that I want to run a JUnit test Called BinarySearchTest. When I run this I get the simple error
Test BinarySearchTest FAILED
I know my Unit test is ok because it tests nothing.
public class BinarySearchTest extends TestCase
{
public void test()
{
}
}
Even if I put the following in my test target I still get the same error
<test name="AtestThatDoesNotExistTest" />
result =
Test AtestThatDoesNotExistTest FAILED
I would have expected a classNotFound error so there is obviously something fundamentally wrong with my Ant XML
JUnit jar is being picked up ok because if it's not in the classpath I will get the error
The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
Update I modified my target to include
<formatter type="brief" usefile="false" />
<test name="com.swaserver.junit.BinarySearchTest" />
test:
[junit] Testsuite: com.swaserver.junit.BinarySearchTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1.878 sec
[junit] ------------- Standard Output ---------------
[junit] Initializing Binary search class
[junit] Binary search class initialized
[junit] ------------- ---------------- ---------------
BUILD SUCCESSFUL Total time: 2 seconds
Now I can see that my test is actually run. However I get a class not found unless I specify the fully qualified class name for my unit test. Why would this be?