Menu

disposeWindow() kills swingui TestRunner?

Help
Anonymous
2001-12-29
2002-01-02
  • Anonymous

    Anonymous - 2001-12-29

    I'm trying to retrofit an existing app with JFCUnit as a proof of concept to skeptical maangement. The code looks like this:

    JFrame frame;
    JFCTestHelper helper;

    protected void setUp()
    {
        helper = new JFCTestHelper();  
    }
       
    protected void tearDown()
    {
        helper.disposeWindow(frame, this);   
    }
       
    public void testMenubarPresent()
    {
        frame = new ProductApp();
        frame.show();
        awtSleep(20000);
           
        JMenuBar menuBar = frame.getJMenuBar();
        assertNotNull(menuBar);
    }

    However, on running the test, all that happens is
    that the JUnit swingui TestRunner exits. If I comment out the call to disposeWindow(), the app loads and displays fine, and the test runs and passes.

    Any ideas as to what might be causing this?

    Thanks,
    Michael E.

     
    • Vijay Aravamudhan

      I am guessing that your frame instance implements a windowlistener and you are doing a 'System.exit(0);' on the windowClosed() or windowClosing() method.
      Vijay

       
    • Anonymous

      Anonymous - 2001-12-30

      Yes, it does - the original author wanted to save any changed files before exiting, so he did add a windowListener to catch windowClosing. Should I remove the System.exit(0) call, and with what should I replace it?

      BTW, great work you guys have done - if I can get this problem worked out, I will have enough ammunition to convince management to use JFCUnit with all new development. Thanks!

       
      • Vijay Aravamudhan

        You would probably want a new class (non GUI) in front of your current frame class (ProductApp) which does the system.exit() by listening to the window close of the frame class. Then you should delete the call to system.exit() from the current frame. That way, you would "launch" the app by calling the new class and the tests would still work without exiting.
        Vijay

         
    • Dean Hiller

      Dean Hiller - 2002-01-02

      I personally put a variable in the class that exits called isUnitTesting.  I set this variable inside my test case.  In the window listener class, I put if(!isUnitTesting) System.exit(0);
      System.exit(0) exits the JVM, so if you don't have this, any tests after this test would not be run.  Basically System.ext(0) will kill all windows including the testrunner GUI.
      Dean

       

Log in to post a comment.