testng无法从ant加载测试类

Ada*_*tan 5 java ant testng classpath

我正在尝试从Ant运行TestNG测试.阅读手册后,我想出了:

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="../../lib/testng-6.8.1.jar"/>
<target name="testng" depends="compile-tests" description="Run testng test suite">      

<fileset id="mixed.tests" dir="${bin.main}">
    <include name="**/*Test.*"/>
</fileset>

<testng mode="mixed" classfilesetref="mixed.tests" 
    verbose="5"
    failureProperty="tests.failed" outputdir="/tmp/report">
    <classpath>
        <fileset dir="../../lib" includes="*.jar"/>
        <fileset dir="../../java/bin/" includes="**/*.class"/>
    <fileset dir="/home/y/lib/jars" excludes="junit*jar,messagebus-disc-parent.jar" includes="**/*.jar" description="all jars installed by dependent pacakges" />
    </classpath>
</testng>
Run Code Online (Sandbox Code Playgroud)

当我运行它失败时:

   [testng] 'org.testng.TestNG'
   [testng] '@/tmp/testng8260935716887369607'
   [testng]
   [testng] The ' characters around the executable and arguments are
   [testng] not part of the command.
   [testng] Exception in thread "main" org.testng.TestNGException:
   [testng] Cannot load class from file: /home/adamatan/SOME_PATH_THAT_EXISTS/functional/EnforceBasicFilteringTest.class
   [testng]     at org.testng.internal.ClassHelper.fileToClass(ClassHelper.java:600)
   [testng]     at org.testng.TestNG.configure(TestNG.java:1393)
   [testng]     at org.testng.TestNG.privateMain(TestNG.java:1354)
   [testng]     at org.testng.TestNG.main(TestNG.java:1333)
   [testng] The tests failed.
Run Code Online (Sandbox Code Playgroud)

我已经尝试过的:

文件和权限:

/home/adamatan/SOME_PATH_THAT_EXISTS/functional/EnforceBasicFilteringTest.class:

  • 出现在类路径打印输出中(它很长,所以我不把它放在这里).
  • 由编译目标创建,因此它是非空的,并且ant可以读取其内容.
  • ls -l- 文件给出 -rw-r--r-- 1 adamatan users 4548 Nov 21 12:19

模式类型:

试过testng mode="testng"testng mode="mixed".两者都失败了同样的错误.

为什么testng不能读取刚刚创建的有效类文件?

小智 1

这里只是一个黑暗中的镜头,但从我读到的来看,TestNG 将作为一个分叉进程启动(来自http://testng.org/doc/ant.html):

此任务运行 TestNG 测试,并且始终在分叉 JVM 中运行。

因此,您可能需要添加 testng 任务的代码路径。还要确保 Java 代码的编译发生在调用 TestNG 之前。

请参阅此处,了解遇到相同问题的人的示例:

https://groups.google.com/forum/#!topic/testng-users/Lc2Pcj7B9C4