DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Ant + JUnit: NoClassDefFoundError问题解决办法


使用Ant+JUnit跑测试用例时如果出现“NoClassDefFoundError”问题,注意一下classpath里的JUnit版本是否为4.5,如果是将其替换为4.0或者4.8。 参见: http://stackoverflow.com/questions/1171264/ant-junit-noclassdeffounderror

使用标签运行JUnit测试时,test的name属性要写类的全名,否则会报“ NoClassDefFoundError”错误,例如:

如果name写成“ AdminFilterTest ”,则出 “ NoClassDefFoundError”错误 。

的子标签中,若需要引用class文件,使用\({test.class.dir}"/>,其中test.class.dir定义为: <property name="test.class.dir" value="\){build.dir}/test"/> 若需要引用jar文件,则使用,其中"lib.path"定义为:

完整的测试任务实例如下: \({test.src.dir}" destdir="\){test.class.dir}" classpathref="lib.path" classpath="\({build.class.dir}" encoding="GBK" optimize="off" debug="on"/> <junit printsummary="yes" haltonfailure="no"> <classpath> <pathelement path="\){test.class.dir}"/> \({build.class.dir}"/> <path refid="lib.path"/> </classpath> <test name="com.boco.godu.gapi.AdminFilterTest" todir="\){test.xml.result}"> \({test.report.dir}"> <fileset dir="\){test.xml.result}">



Published

Dec 15, 2010

Last Updated

Dec 15, 2010

Category

Tech

Tags

  • Ant 21
  • JUnit 10
  • NoClassDefFoundError 3

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor