![](/img/trans.png)
[英]TestNG: All subsequent Test classes are skipped when @BeforeClass method fails?
[英]testng fails to load test classes from ant
我正在尝试从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>
当我运行它失败时:
[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
:
ls -l
-ing文件给出-rw-r--r-- 1 adamatan users 4548 Nov 21 12:19
试过testng mode="testng"
和testng mode="mixed"
。 两者都失败了同样的错误。
为什么testng不能读取刚刚创建的有效类文件?
通过向类路径添加测试本身所在的目录(在您的情况下看起来像${bin.main}
),我解决了同样的问题。
只是在黑暗中拍摄,但从我读到的TestNG将作为分叉过程启动(来自http://testng.org/doc/ant.html ):
此任务运行TestNG测试,并始终在分叉的JVM中运行。
因此,您可能希望为testng任务添加代码路径。 还要确保在调用TestNG之前编译Java代码。
请点击此处查看遇到同一问题的人的示例:
https://groups.google.com/forum/#!topic/testng-users/Lc2Pcj7B9C4
一些建议:
创建了类文件,但它无效且无法读取。 你能检查一下你可以用它吗? 例如, javap -p $class
为您提供方法列表,而不是错误?
一个java(具有更高版本)创建文件,另一个(具有更低版本)正在尝试加载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.