从 build.xml 运行 jUnit 测试时出现 ClassNotFound 异常 [英] ClassNotFound Exception when running jUnit test from build.xml

查看:26
本文介绍了从 build.xml 运行 jUnit 测试时出现 ClassNotFound 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试配置构建文件以使用 ant xml 文件运行 junit 测试.但是遇到了 ClassNotFound 异常.以下是运行 jUnit 测试的部分代码:

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>

如何解决这个问题?

推荐答案

看起来您的测试类不是类路径的一部分.

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

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

请查看此模板 build.xml:https://github.com/mlacona/java-junit-template-project/blob/master/build.xml

这篇关于从 build.xml 运行 jUnit 测试时出现 ClassNotFound 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆