【问题标题】:testng fails to load test classes from anttestng 无法从 ant 加载测试类
【发布时间】:2015-08-22 16:37:56
【问题描述】:

我正在尝试从 Ant 运行 TestNG 测试。看完the manual, I came up with

<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>

当我运行它时失败:

   [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.

我已经尝试过的:

文件和权限:

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

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

模式类型:

尝试了testng mode="testng"testng mode="mixed"。两者都因相同的错误而失败。

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

【问题讨论】:

  • 抱歉我的愚蠢问题(我不是 Ant 的高级用户)。为什么写excludes="junit*jar,是不是有效的表达方式?
  • @olyv 这是一个有效的表达式。我想确保测试使用 TestNG 类,而不是具有相同名称的 JUnit 类。

标签: java ant classpath testng


【解决方案1】:

通过将测试本身所在的目录添加到类路径中,我也解决了同样的问题(在你的情况下看起来像 ${bin.main})。

【讨论】:

    【解决方案2】:

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

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

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

    有关遇到相同问题的人的示例,请参见此处:

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

    【讨论】:

      【解决方案3】:

      一些建议:

      1. 类文件已创建,但无效且无法读取。你能检查一下你可以使用它吗?例如,javap -p $class 是否给你方法列表,而不是错误?

      2. 一个java(更高版本)创建文件,另一个(更低版本)正在尝试加载它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-18
        • 1970-01-01
        • 2014-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多