Sometimes my JUnit tests do not finish when run in IDEA - they stop abruptly after tearDown() and IDEA displays the the "test interrupted" icon for the halted test case.
Stepping through code, I've found that there is an IOException occuring at the point where the JUnitStarter sends the results back to IDEA via the stdout. The problem is that the IOException throws "silently" and I can't use the debugger to get the exception message.
The problem stems from the fact that our product, TCM 6, redirects the stdout to our own logging facility. Apparently, whatever we do with stdout causes IDEA's junit integration feature to "choke." I've determined (via email with your support team) that IDEA's JUnitStarter embeds test result data in the System.out stream, resulting in this behavior.
When I run the tests using Maven 2, this behavior does not occur.
I've seen this behavior in both IDEA 5.1.2 and 7.0.3.
Below is an example stack trace (from IDEA 5.1.2) where the IOException occurs. I was using Sun Java 1.5.0_09.
java.io.PrintStream.write(PrintStream.java:421)
java.io.FilterOutputStream.write(FilterOutputStream.java:80)
com.intellij.rt.execution.junit2.segments.SegmentedOutputStream.writeNext(SegmentedOutputStream.java:61)
com.intellij.rt.execution.junit2.segments.SegmentedOutputStream.processPacket(SegmentedOutputStream.java:54)
com.intellij.rt.execution.junit2.segments.PacketWriter.sendThrough(PacketWriter.java:29)
com.intellij.rt.execution.junit2.segments.Packet.send(Packet.java:41)
com.intellij.rt.execution.junit2.TestResultsSender.endTest(TestResultsSender.java:49)
junit.framework.TestResult.endTest(TestResult.java:72)
junit.framework.TestResult.run(TestResult.java:111)
junit.framework.TestCase.run(TestCase.java:120)
junit.framework.TestSuite.runTest(TestSuite.java:230)
junit.framework.TestSuite.run(TestSuite.java:225)
junit.textui.TestRunner.doRun(TestRunner.java:121)
com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:58)
junit.textui.TestRunner.start(TestRunner.java:185)
com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:98)
com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
From: Eugene Zhuravlev <jeka@intellij.com>
To: "Serge Baranov" <serge@jetbrains.com>
Date: Monday, September 3, 2007, 9:52:52 PM
Subject: [IDEA-Problem] IntelliJ abruptly halts JUnit test (problem with
sending results to IDEA)
Looks like the stream is closed, while JUntStarter is in the process of sending data. Is it possible to make sure that the stream is not closed until the starter is finished? Another option is to try to insert a delay in tearDown() or at the end of the test, so that JUnitStarter will have extra time to send its stuff.
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"
NOTE: (I scattered some Thread.sleep() calls throughout the test (both in the test cases and the tearDown()) - but it still had the same result.)