Ant support: Eclipse wins

Eclipe or Netbeans? Netbeans is great for the Swing designer, it is my favorite tool for desktop UI design.
However for the rest of the tasks I prefer Eclipse. Eclipse integration with Ant is very good as the editor reads all the dependencies within the buid.xml and provides all the autocompletion just by loading the project (create a new Java project from existing Ant file). Running the JUnit targets from the build.xml works fine which is something I couldn't make with Netbeans. Netbeans didn't find the tests.
Once the project is loaded go to Window menu -> Show view -> Ant. See the Ant view at your right hand side and click on the tiny "Add Buildfiles" button on the top of it. Select the build.xml and you're done.

My JUnit configuration (slightly modified from this post):

  1.  
  2. <path id="classpath.unit_test">
  3. <pathelement location="${lib}/comun/junit-3.8.2.jar" />
  4. <pathelement path="${build.datos}"/>
  5. <pathelement path="${build.cliente}"/>
  6. <pathelement location="./test/unitarios" />
  7. <fileset dir="${lib.comun}">
  8. <include name="**/*.jar"/>
  9. </fileset>
  10. <fileset dir="${lib}/cliente">
  11. <include name="**/*.jar"/>
  12. </fileset>
  13. <fileset dir="${lib}/control">
  14. <include name="**/*.jar"/>
  15. </fileset>
  16. </path>
  17.  
  18. <target name="unit_test.compile" depends="unit_test.clean">
  19. <javac srcdir="./test/unitarios"
  20. verbose="yes"
  21. includeAntRuntime="true"
  22. debug="on" debuglevel="lines,vars,source">
  23. <classpath refid="classpath.unit_test"/>
  24. </javac>
  25. </target>
  26. <target name="unit_test.clean">
  27. <delete verbose="yes">
  28. <fileset dir="./test/unitarios" includes="**/*.class" />
  29. </delete>
  30. </target>
  31.  
  32. <target name="unit_tests.run" depends="unit_test.compile"
  33. description="Run unit tests">
  34. <junit showoutput="yes"
  35. printsummary="yes"
  36. filtertrace="off" fork="yes"
  37. haltonfailure="no">
  38. <classpath refid="classpath.unit_test" />
  39. <formatter type="plain"/>
  40. <batchtest>
  41. <fileset dir="./test/unitarios/">
  42. <include name="**/*Tests.class"/>
  43. </fileset>
  44. </batchtest>
  45. </junit>
  46. </target>
  47.  

Exceptions' stack traces are sent to a file in the project main folder called Test-your_test_case_name.txt
For better output in the Eclipse Console while running the tests, click over the unit_test.run target with the right mouse button (in the Ant view) then "Run as" and then "Ant Build..." and set "-v" in the arguments in the "Main" tab. Note the "debug=on" in the javac target (thanks Nilesh).
The test execution summary is presented for each TestCase rather than altogether so scroll up to watch all
the results (I was wondering why just one TestCase was ran)

Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.