ClassNotFound Exception when running jUnit test fr

2019-09-07 08:52发布

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?

标签: java xml ant junit
1条回答
Emotional °昔
2楼-- · 2019-09-07 09:20

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

查看更多
登录 后发表回答