1 Reply Latest reply on Apr 16, 2010 5:38 AM by Aslak Knutsen

    TestEnricher.teardown()

    Andrew Rubinger Master

      Given:

       

      public interface TestEnricher
      {
         /**
          * 
          * @param testCase
          */
         void enrich(Object testCase);
      }

       

      This is effectively a lifecycle method of sorts for Test Cases.  Before executing, we have the opportunity to allocate resources and inject them into the supplied instance.  I'd like to propose an addition to TestEnricher which provides for a teardown; this will allow us to safely close anything we may have opened.

       

      A more concrete case:  I've got a working Container implementation for JBoss Reloaded.  The enrichment process piggybacks upon Microcontainer; everything is injected into the test instance by installing the instance itself into MC.  However, at the end of the test run we go to shut down the Kernel, and it spews out an Exception because we're shutting down before we've undeployed the test instance.  A "teardown" method would give us the hook to do this.

       

      In short, what goes up must come down.   With some approval I'll add this method and refactor the dependent modules with some NOOP implementations so nothing breaks.

       

      S,

      ALR

        • 1. Re: TestEnricher.teardown()
          Aslak Knutsen Master

          See: http://community.jboss.org/message/537913#537913

           

          With the new core, a possible solution could be to let the TestEnricher have access to the TestContext. With this it can register it self for a callback in the @After lifecycle.

           

          {code:java}

           

          public class InstallTestCase implements TestEnricher
          {
             @Override
             public void enrich(final TestContext context, final Object testCase)
             {
                MCServer server = context.get(MCServer.class);
                server.install(testCase);
               
                context.register(After.class, new UninstallTestCase());
             }
            
             public static class UninstallTestCase implements EventHandler<TestContext, TestEvent>
             {
                @Override
                public void callback(TestContext context, TestEvent event) throws Exception
                {
                   MCServer server = context.get(MCServer.class);
                   server.uninstall(event.getTestInstance());
                }
             }
          }

           

          {code}