0

我有一个 Java 项目,它有一个“src”目录,用于存放与我的项目直接相关的代码,还有一个“test”目录,它是针对“src”目录中的代码运行的 JUnit 测试。目录结构如下:

ROOT/src/com/mycompany/decoders/qDecoder/.....

ROOT/test/com/mycompany/decoders/qDecoder/.....

这两个目录具有完全相同的包结构。

以下是目标和相关的 JUnit 信息:

<property name="src_classes_dir" value="./bin"/>
<property name="test_classes_dir" value="./binTest"/>

<path id="junit.classpath">
  <pathelement location="${src_classes_dir}"/>
  <pathelement location="${test_classes_dir}"/>
  <pathelement location="${CommonJarPath}/JUnit/junit.jar"/>
  <pathelement location="${CommonJarPath}/JavaMail/mailapi.jar"/>
  <pathelement location="${CommonJarPath}/JavaMail/smtp.jar"/>
  <pathelement location="${CommonJarPath}/CommonsLang3/commons-lang3.jar"/>
  <pathelement location="${CommonJarPath}/JDBC/inetsoftware/merlia/8.0.2/Merlia.jar"/>
  <pathelement location="${CommonJarPath}/JodaTime/joda-time.jar"/>
</path>

<property name="test_dir" value="./test"/>  

<target name="junit" description="Run JUnit tests" depends="compile_source, compile_test">        
  <junit fork="yes" haltonfailure="yes" haltonerror="yes" showoutput="yes">
    <formatter type="plain" usefile="no"/>
    <classpath refid="junit.classpath"/>                
    <batchtest>         
      <fileset dir="${test_dir}" />
    </batchtest>    
  </junit>
</target>

所以,我的测试文件(*.java)${test_dir}. 测试类在 中${test_classes_dir},测试类在 中${src_classes_dir}。两者都在junit.classpath参考文献中列出。

所有的目标都完成了,'clean'、'prep'、'src_compile' 和 'test_compile' 直到 'junit' 目标,然后我ClassNotFoundException在第一个 test中得到一个AMCiBitsTest。所以它知道测试,但由于某种原因找不到它的类。

这是异常跟踪:

junit:
    [junit] Testsuite: com.amci.util.AMCiBitsTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit]
    [junit]     Caused an ERROR
    [junit] com.amci.util.AMCiBitsTest
    [junit] java.lang.ClassNotFoundException: com.amci.util.AMCiBitsTest
    [junit]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    [junit]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    [junit]     at java.security.AccessController.doPrivileged(Native Method)
    [junit]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    [junit]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:190)
    [junit]

我难住了。我究竟做错了什么?为什么这不能运行AMCiBitsTest测试和所有其他测试?

4

1 回答 1

0

我已经修好了。可以说我在构建文件中出现了语法错误,而上面发布的内容确实有效。我很抱歉,并感谢您的问题和您的时间。

于 2013-09-25T14:25:25.513 回答