Menu

cleanup() kills JUnit test thread

Help
2005-08-15
2013-04-09
  • Pamela Jones

    Pamela Jones - 2005-08-15

    When I call TestHelper.cleanup() to get rid of any components or windows still possibly open the junit test thread is killed - thereby preventing other tests from running.  I've tracked the problem down to line 493 of TestHelper where a window close event is posted to the event queue.  Since the GUI is running on a different thread from the tests I can't see why this would happen.  Any ideas?

    Also, by not running cleanup I have to manually dispose of windows but for some reason menus hang around in memory, so subsequent tests that run the application increase the number of menu components and cause problems in the tests.

     
    • David

      David - 2006-01-22

      This may be occuring because your application has a defaultCloseOperation of JFrame.CLOSE_ON_EXIT, so the JVM exits on closing it as it was the last displayable window.  Perhaps you could try using JFrame.DISPOSE_ON_EXIT instead, e.g.:

      public class MyTest extends JFCTestCase {
        :
        public void setUp() {
          :
          app = new TestApp(); // extends JFrame
          app.setDefaultCloseOperation(JFrame.DISPOSE_ON_EXIT);
          :
        }
        :
      }

      For more information see:

      http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html

      ...and:

      http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation\(int)

       

Log in to post a comment.