【发布时间】: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 类。