I add a build script to the ant to run the JUnit unit tests. Created a target:

<!-- Run the JUnit Tests --> <target name="junit" depends="compile"> <junit printsummary="on" haltonfailure="no"> <classpath> <fileset dir="${junit.dir}" includes="junit-4.10.jar"/> </classpath> <formatter type="plain" /> <batchtest todir="${test.report.dir}"> <fileset dir="${unittest.dir}"> <include name="**/*.java" /> </fileset> </batchtest> </junit> </target> 

but I get an error for all tests with this text:

 Testsuite: Application.Enums.Timeline.TrackLabelsTest Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec Caused an ERROR Application.Enums.Timeline.TrackLabelsTest java.lang.ClassNotFoundException: Application.Enums.Timeline.TrackLabelsTest at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138) 

Apparently, he can not find the test itself, right? I can not figure out whether to compile in the compilation target and a folder with tests, ie $ {unittest.dir}? How does it work specifically - compiles all java-files in the $ {unittest.dir} folder by * / .java for this type (that is, all), and runs the JUnit test?

Debut log Anta also did not give anything interesting.

  • if my memory serves me, in this version, as you are running the test, you don’t need to compile anything, just specify the source folder - jmu

2 answers 2

Tests must be included in the classpath and compiled.

  • Compiled, classpas turned into this: <classpath> <fileset dir = "$ {junit.dir}" includes = "junit-4.10.jar" /> <fileset dir = "$ {unittest.dir}" includes = " * / .java "/> </ classpath> but so far to no avail ( - Anton Feoktistov
  • Happened! :) <classpath> <fileset dir = "$ {junit.dir}" includes = "junit-4.10.jar" /> <pathelement location = "$ {build.dir}" /> </ classpath> Added to class path to crashed classes :) - Anton Feoktistov

In the end, this is what happened:

 <!-- Run the JUnit Tests --> <target name="junit" depends="compile"> <junit printsummary="on" haltonfailure="no"> <classpath> <fileset dir="${junit.dir}" includes="junit-4.10.jar"/> <pathelement location="${build.dir}"/> </classpath> <formatter type="plain" /> <batchtest todir="${test.report.dir}"> <fileset dir="${unittest.dir}" /> </batchtest> </junit> </target> 

http://www.daniweb.com/software-development/java/threads/216217/how-to-use-java-to-call-ant-junit-target# - this resource helped a lot with the Barmaley answer :)