You will have to compile your test(s) and add the test classes folder to the junit classpath. I suggest you create a test folder under code.
<target name="build-test" >
<mkdir dir="code/test-classes"/>
<javac includeantruntime="false" srcdir="code/test" destdir="code/test-classes" classpathref="classpath" />
</target>
<target name="test" depends="build, build-test">
<junit printsummary="yes" showoutput="yes">
<classpath>
<pathelement path="code/lib/junit-4.11.jar"/>
<pathelement path="code/lib/hamcrest-core-1.3.jar"/>
<pathelement path="code/build"/>
<pathelement path="code/test-classes"/>
</classpath>
<batchtest >
<fileset dir="code/test" includes="test.java"/>
</batchtest>
<formatter type="plain" usefile="false" />
</junit>
</target>