使用ant 1.9.4运行junit4测试(使用fork =“true”jvm崩溃)

时间:2016-08-01 13:13:53

标签: junit ant

我正在尝试使用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”运行单元测试时,没有问题。 ant任务如下所示

<junit failureproperty="testCasesFailed" jvm="C:\Program Files\Java\jdk1.8.0_40\bin\java" 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测试应该没有开箱即用的问题 - 任何人都知道这里可能出现什么问题?

1 个答案:

答案 0 :(得分:0)

问题是,在(非常长的)类路径中有一个旧版本的ant贡献了一个旧版本的ant,它神秘地使JVM崩溃。