ClassNotFound Exception when running jUnit test from build.xml

一个人想着一个人 提交于 2019-12-11 21:28:35

问题


I am currently trying to configure a build file to run junit test using ant xml file. However ClassNotFound Exception is being encountered. The following is part of the code that shall run the jUnit test:

<target name="junitreport" >
    <junit printsummary="yes" haltonfailure="no">
      <classpath refid="JUnit 4.libraryclasspath"/>     
      <formatter type="plain"/>
      <formatter type="xml"/>
      <batchtest todir="${junit.output.dir}">
        <fileset dir="src/tests">
          <include name="CalculatorTest.java"/>
        </fileset>
     </batchtest>
  </junit>
</target>

How this can be solved?


回答1:


It looks like your test classes are not part of the classpath.

<classpath>
  <path refid="JUnit 4.libraryclasspath"/>
  <pathelement location="${test.build.dir}"/>
</classpath>

Please have a look at this template build.xml: https://github.com/mplacona/java-junit-template-project/blob/master/build.xml



来源:https://stackoverflow.com/questions/22923861/classnotfound-exception-when-running-junit-test-from-build-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!