Today I was writing a unit test which instantiated a class, which started a thread to do some stuff. I was hoping to test the side effect of that thread. However, to my surprise, I realized that Eclipse would forcibly terminate the test after the test method exited, even before the thread completed it's work. I wrote a simple test to show this. import com.sun.org.apache.xpath.internal.operations.And; import junit.framework.TestCase; import junit.textui.TestRunner; /** * This class shows that Eclipse's JUnit test case runner will forcibly terminate * the JVM and all running threads */ public class ThreadTest extends TestCase { static Runnable run = new Runnable() { public void run() { int cnt = 0; while(true) System.out.println(cnt++); } }; public void testThread() { Thread t = new Thread(run); t.start(); } public static void main(String args[]) { TestRunner runner = new TestRunner(); runner.run(ThreadTest.class); } } This cl...
Write Awesome User Manuals and Tutorials for Software Products