Мои тесты JUnit не выполняются из-за ClosedByInterruptException , после завершения теста он не может написать свой отчет о тестировании и просто останавливается со следующим исключением:
[junit] Exception in thread "main" Unable to write log file
[junit] at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.endTestSuite(XMLJUnitResultFormatter.java:197)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireEndTestSuite(JUnitTestRunner.java:860)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:579)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1205)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1021)
[junit] Caused by: java.nio.channels.ClosedByInterruptException
[junit] at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)
[junit] at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:200)
[junit] at java.nio.channels.Channels.writeFullyImpl(Channels.java:78)
[junit] at java.nio.channels.Channels.writeFully(Channels.java:101)
[junit] at java.nio.channels.Channels.access$000(Channels.java:61)
[junit] at java.nio.channels.Channels$1.write(Channels.java:174)
[junit] at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
[junit] at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement$DelayedFileOutputStream.flush(FormatterElement.java:394)
[junit] at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)
[junit] at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
[junit] at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
[junit] at java.io.BufferedWriter.flush(BufferedWriter.java:254)
[junit] at org.apache.tools.ant.util.DOMElementWriter.openElement(DOMElementWriter.java:368)
[junit] at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:209)
[junit] at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:222)
[junit] at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:222)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.endTestSuite(XMLJUnitResultFormatter.java:195)
[junit] ... 4 more
Яиспользуя ant-junit-1.10.5-jar .Фрагмент метода endTestSuite :
if (out != null) {
Writer wri = null;
try {
wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
new DOMElementWriter().write(rootElement, wri, 0, " ");
} catch (final IOException exc) {
throw new BuildException("Unable to write log file", exc);
}
Моя муравьиная цель JUnit выглядит следующим образом:
<junit dir="${test.path}/${test.dir}" fork="on" forkmode="once" haltonfailure="${junit.halt.on.failure}" outputtoformatters="true" printsummary="on" showoutput="true">
<sysproperty key="junit.aspectj.dump" file="woven-classes" />
<!--
<sysproperty key="junit.cobertura.agent" value="${junit.cobertura.agent}" />
-->
<sysproperty key="junit.code.coverage" value="${junit.code.coverage}" />
<sysproperty key="junit.debug" value="${junit.debug}" />
<sysproperty key="cluster.link.primary.node" value="true" />
<sysproperty key="net.sourceforge.cobertura.datafile" file="${test.path}/test-coverage/${test.type}/cobertura.ser" />
<jvmarg line="${junit.debug.jpda}" />
<jvmarg line="${junit.profile.agent}" />
<!--
<jvmarg line="${junit.cobertura.agent}" />
-->
<jvmarg value="-Xmx${junit.java.mx}" />
<jvmarg value="-Dexternal-properties=${test.properties}" />
<jvmarg value="-Dfile.encoding=UTF-8" />
<jvmarg value="-Djava.net.preferIPv4Stack=true" />
<jvmarg value="-Duser.timezone=GMT" />
<classpath location="${test.path}/test-coverage" />
<classpath refid="test.classpath" />
<formatter type="brief" usefile="false" />
<formatter type="xml" />
<batchtest fork="yes" todir="${test.path}/test-results/${test.type}">
<fileset dir="${test.path}/test-classes/${test.dir}" includes="**/${test.class}.class">
<exclude name="${test.excludes}" />
<filename regex="${junit.test.excludes}" negate="true" />
</fileset>
</batchtest>
</junit>