在 Ant build.xml 中执行 JUnit 测试 - java.lang.NoClassDefFoundError

问题描述 投票:0回答:2

我尝试使用 Ant build.xml 运行 JUnit 测试,但收到 java.lang.NoClassDefFoundError,我应该如何配置我的 build.xml 文件才能使其工作?

apps/deploy/APP-INF/classes/test -> 中编译的类是我的项目文件夹的这个路径

<target name="JUnitTest">
  <junit>
    <classpath>
      <pathelement path="apps/deploy/APP-INF/classes/test" />
      <pathelement location="apps/deploy/APP-INF/lib/junit.jar"/>
    </classpath>    
    <batchtest>
       <fileset dir="apps/deploy/APP-INF/src/test">
            <include name="**/*.java" />
       </fileset>
    </batchtest>
    <formatter type="brief" usefile="false"/>
  </junit>
</target>   

我的错误如上所示。请感谢任何帮助!

java junit4 noclassdeffounderror
2个回答
0
投票

请指定您的

test.dir
,如下所示,并在您的测试目标中正确引用它

<path id="classpath">
    <pathelement path="${java.class.path}"/>
    <fileset dir="${lib.dir}" includes="*.jar"/>
    <fileset dir="${build.dir}" includes="**/*.class"/>
    <fileset dir="${test.dir}" includes="**/*.class"/>
</path>

---   
<target name="test" depends="compile">
    <junit printsummary="on" haltonfailure="yes">
        <classpath refid="classpath"/>
        <formatter type="plain"/>
        <batchtest todir="${build.dir}">
            <fileset dir="${test.dir}" includes="**/*Test*.java"/>
        </batchtest>
    </junit>
</target>

0
投票

已解决:问题是文件集和名称中的目录错误。我把它改成这样:

<batchtest>
    <fileset dir="${src.dir}/APP-INF/src">
        <include name="test/*.java"/>
    </fileset>
</batchtest>
© www.soinside.com 2019 - 2024. All rights reserved.