新来的Ant,ClassNotFoundException的使用JUnit [英] New to Ant, ClassNotFoundException with JUnit

查看:143
本文介绍了新来的Ant,ClassNotFoundException的使用JUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在抓我的头在这一段时间,现在(用Google搜索了一堆,通过其他相关看起来是如此的职位无济于事)。我有由两个文件一个Java程序,逻辑测试测试包含大约一百JUnit测试,我已经通过调用的javac *的.java 其次的Java org.junit.runner.JUnitCore测试。然而,当我跑我的的build.xml 用一个简单的蚂蚁-verbose测试(为了进行输出,因为我是新来这一切),我得到以下的输出:

I've been scratching my head over this for a while now (Googled a bunch, looked through other related SO posts to no avail). I have a Java program comprised of two files, Logic and Tests. Tests contains about a hundred JUnit tests, and I've gotten 100% success rate with said tests by calling javac *.java followed by java org.junit.runner.JUnitCore Tests. However when I run my build.xml with a simple ant -verbose test (in order to follow the output since I'm new to all this), I get the following output:

[junit] Testsuite: Tests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] 
[junit] Null Test:  Caused an ERROR
[junit] Tests
[junit] java.lang.ClassNotFoundException: Tests
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:247)
[junit] 
[junit] 
[junit] Test Tests FAILED

BUILD SUCCESSFUL

我的的build.xml 如下:

<project name="ETL_Automation" default="test" basedir=".">

<path id="classpath.base">
</path>

<path id="classpath.test">
  <pathelement location="${basedir}/mysql-connector-java-5.1.18-bin.jar" />
  <pathelement location="${basedir}/junit-4.10.jar"/>
  <path refid="classpath.base" />
</path>

<target name="compile">
  <javac srcdir="${basedir}">
    <classpath refid="classpath.test"/>
  </javac>
</target>

<target name="test" depends="compile">
  <junit fork="no">
    <classpath refid="classpath.test" />
    <formatter type="brief" usefile="false" />
    <batchtest>
      <fileset dir="${basedir}/" includes="Tests.class" />
    </batchtest>
  </junit>
</target>

<target name="clean" depends="test">
  <delete>
    <fileset dir="${basedir}" includes="*.class"/>
  </delete>
</target>

的目录结构是pretty简单。 Tests.java Logic.java 的JUnit 4.10.jar 使用mysql-connector-java的5.1.18-bin.jar 的build.xml 和引用的.properties 文件都在同一个文件夹。在java code引用外部文件,但这些都是无关的这一具体问题。我不知道,如果类路径可能是这个问题的原因(我敢pretty说服我目前已经不工作)。

The directory structure is pretty straightforward. Tests.java, Logic.java, junit-4.10.jar, mysql-connector-java-5.1.18-bin.jar, build.xml, and a referenced .properties file are all in the same folder. The java code references external files but those are unrelated to this particular issue. I don't know if the classpath could be the cause of this issue (as I'm pretty convinced what I currently have doesn't work).

谢谢!

推荐答案

您需要用 Tests.class 添加目录到 classpath.tests 类路径(即 $ {BASEDIR} 在你的设置)

You will need to add the directory with the Tests.class to the classpath.tests classpath (which is ${basedir} in your setup)

尝试:

<path id="classpath.test"> 
  <pathelement location="${basedir}/mysql-connector-java-5.1.18-bin.jar" /> 
  <pathelement location="${basedir}/junit-4.10.jar"/> 
  <pathelement location="${basedir}" /> 
  <path refid="classpath.base" /> 
</path>

这篇关于新来的Ant,ClassNotFoundException的使用JUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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