我正试图用ant 1.9.4运行junit 3和junit 4测试。在junit任务中使用fork="true"时,我遇到了奇怪的错误(jvm)崩溃:
12:40:58,686 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Testcase: testAdd took 0,005 sec
12:40:58,686 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Testcase: testAdd1 took 0 sec
12:40:58,755 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Testsuite: vai.testproduct.TestCalculator3
12:40:58,755 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
12:40:58,755 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO -
12:40:58,756 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Testcase: null took 0 sec
12:40:58,756 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Caused an ERROR
12:40:58,756 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
12:40:58,756 [master>Build>Run and publish Unit Tests and Coverage>Run Tests@lnzvt-fls0010:80] INFO - [junit] junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
当我用fork="false"运行单元测试时,没有问题。蚂蚁任务如下
<junit failureproperty="testCasesFailed" jvm="C:Program FilesJavajdk1.8.0_40binjava" fork="true" clonevm="true" showoutput="false" haltonfailure="false" haltonerror="false" timeout="600000" printsummary="true" includeantruntime="true">
<!-- NOTE timeout of 10 minutes-->
<jvmarg line="-Djava.awt.headless=true" />
<jvmarg value="-DbuildDate=${buildDate}" />
<jvmarg value="-XX:ErrorFile=./myfile%.txt" />
<jvmarg value="-XX:+PrintCommandLineFlags" />
<!--<jvmarg value="-XX:+UnlockCommercialFeatures"/>
<jvmarg value="-XX:+FlightRecorder" />
<jvmarg value="-XX:FlightRecorderOptions=dumponexit=true,defaultrecording=true,dumponexitpath=.,loglevel=info" />-->
<classpath refid="test.classpath" />
<formatter type="xml" />
<formatter type="plain" usefile="false" />
<batchtest todir="${tests.report.dir}">
<fileset dir="${target.tests.dir}" includes="${tests.includes}" excludes="${tests.excludes}" />
</batchtest>
</junit>
如果没有jvm属性,它也不起作用。test.classpath似乎也正确地填充了junit 4。
这个问题与单元测试中的代码无关:即使测试只包含assertEquals(true,true),jvm也会崩溃。jvm不会写入崩溃文件。当我使用flightrecorder运行jvm时,会出现死锁,并且在达到junit ant任务超时之前,它永远不会终止。
远程调试也不起作用,运行测试的jvm将在调试器连接后立即终止。
基本上,我使用了junit ant任务中所有可用的参数,但它们都不起作用(showoutput="true"/"false"clonevm="true"/"false"等)
在stackoverflow上的类似问题中,有人建议System.exit()或OutOfMemoryException可能会导致问题,但这里绝对不是这样。
用ant运行junit 4测试应该不会出现任何问题——有人知道这里的问题是什么吗?
问题是,在(非常长的)类路径中,有一个旧的ant对旧版本的ant的贡献神秘地导致JVM崩溃。