DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Unit Test with JUnit and Ant


I put junit-4.11.jar to $ANT_HOME/lib folder(I didn't set ANT_HOME environment virable), then I can use task in ant script as follows:

\({test.report.dir}"/> <junit printsummary="yes" fork="yes"> <classpath> <pathelement location="\){src.class.dir}"/> \({test.class.dir}"/> <pathelement location="\){lib.dir}/hamcrest-core-1.3.jar" /> \({test.report.dir}" haltonerror="no"> <fileset dir="\){test.dir}">

A pitfall here is that Junit depends on hamcrest(see junit website), but if you put hamcrest-core-1.3.jar to $ANT_HOME/lib, there will be a "Class not found" error. It's probably a bug or version matching problem of junit. You have to put hamcrest jar file in "classpath" element of junit task as above.



Published

May 28, 2013

Last Updated

May 28, 2013

Category

Tech

Tags

  • Ant 21
  • classpath 7
  • Java 106
  • JUnit 10

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor