oneTimeTearDown is not called

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

oneTimeTearDown is not called

Postby eeybye » Mon Nov 12, 2007 3:34 am

In my test caes, I want to perform some one-time setup and tear down ui calls.

oneTimeSetup on my derivered class is called, and I can perform ui clicks.

oneTimeTearDown is not called. How come ??

I have several test classes in my suite, but is only using the oneTimeSetup/TearDown in one test class.

I'm using WindowTesterSWT v. 2.3.0
eeybye
 
Posts: 22
Joined: Fri Jun 22, 2007 12:34 am
Location: Denmark

Postby Phil Quitslund » Tue Nov 13, 2007 9:17 am

The first step to resolving your problem is for us to reproduce it on our end. Here's a test that attempts to verify oneTimeSetup calls. Does it work for you? Can you see a way to modify the test so that it reflects your situation?

Code: Select all
package com.windowtester.test.runtime;

import junit.extensions.UITestCaseSWT;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* A test to verify that one time tear down is getting called as expected.
* <p>
* Copyright (c) 2007, Instantiations, Inc.<br>
* All Rights Reserved
*
* @author Phil Quitslund
*
*/
public class OneTimeTeardownTest extends TestCase {

   public static class TestA extends UITestCaseSWT {

      static int counter;
      
      public TestA() {}
      
      public void testMain() {}

      @Override
      protected void oneTimeSetup() throws Exception {
         ++counter;
      }

      
   }

   public static class TestB extends UITestCaseSWT {
      
      static int counter;
      
      public TestB() {}
      
      public void testMain() {}
      
      @Override
      protected void oneTimeSetup() throws Exception {
         ++counter;
      }
      
   }
      
   public static class TestOneTimeTearDownA extends UITestCaseSWT {
      
      public TestOneTimeTearDownA() {}
      
      public void testTearDown() {
         assertEquals(1, TestA.counter);
      }
   }
   
   public static class TestOneTimeTearDownB extends UITestCaseSWT {
      
      public TestOneTimeTearDownB() {}
      
      public void testTearDown() {
         assertEquals(1, TestB.counter);
      }
   }
   
   public static class TestNoTearDownsB extends UITestCaseSWT {
      
      public TestNoTearDownsB() {}
      
      public void testTearDown() {
         assertEquals(0, TestB.counter);
      }
   }
   
   
   public static TestSuite suite() {
      TestSuite suite = new TestSuite();
      suite.addTestSuite(TestA.class);
      suite.addTestSuite(TestOneTimeTearDownA.class);
      suite.addTestSuite(TestNoTearDownsB.class);
      suite.addTestSuite(TestB.class);
      suite.addTestSuite(TestOneTimeTearDownB.class);
      suite.addTestSuite(TestA.class);
      suite.addTestSuite(TestB.class);
      suite.addTestSuite(TestA.class);
      suite.addTestSuite(TestB.class);
      suite.addTestSuite(TestOneTimeTearDownA.class);
      suite.addTestSuite(TestOneTimeTearDownB.class);
      
      return suite;
      
   }
   
   
   
}



Thanks!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Postby eeybye » Tue Nov 13, 2007 11:07 pm

I have now tried your testcase examples.

Maybe I have not been explaining it well enough.

The oneTimeSetup worked perfectly, it was the oneTimeTearDown which didn't work.

The example below should show what I mean.

Code: Select all
import junit.extensions.UITestCaseSWT;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* A test to verify that one time tear down is getting called as expected.
* <p>
* Copyright (c) 2007, Instantiations, Inc.<br>
* All Rights Reserved
*
* @author Phil Quitslund
*
*/
public class OneTimeTearDownTest extends TestCase {

      public static class TestWTearDown extends UITestCaseSWT {
      public TestWTearDown() {
      }
      
      static int counter;

      @Override
      protected void oneTimeSetup() throws Exception {
         super.oneTimeSetup();
         counter = 10;
      }
      
      public void testCounter() {
         assertEquals(10, counter);
         counter++;
      }
      
      @Override
      protected void oneTimeTearDown() throws Exception {
         super.oneTimeTearDown();
         assertEquals(11, counter);
         counter = 5;
      }
      }
      
      public static class TestWOTearDown extends UITestCaseSWT {
         public TestWOTearDown() {
      }
         
         public void testCounter() {
            assertEquals(5, TestWTearDown.counter);
         }
      }
   
   public static TestSuite suite() {
      TestSuite suite = new TestSuite();
      suite.addTestSuite(TestWTearDown.class);
      suite.addTestSuite(TestWOTearDown.class);
      return suite;
     
   }
}


The second testcase fails because counter is 11, but should be 5 due to the oneTimeTearDown call.
eeybye
 
Posts: 22
Joined: Fri Jun 22, 2007 12:34 am
Location: Denmark

Postby Phil Quitslund » Wed Nov 14, 2007 3:51 am

Aha: No, you're post was actually quite clear --- I just misread it!

The issue here is that the one-time tearDown is only called after all the tests have been run. The reason for this is that the test runner cannot look ahead to see if there are any more tests for a given class to run. Instead, it does it's class teardowns at the end.

In your given use case, this is definitely a limitation in the implementation.

If you need to perform a teardown after a set of tests you might consider defining it in it's own class and adding it to the suite where it belongs.

Hope this helps --- sorry for the confusion!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest