[jboss-dev-forums] [Design of JBoss internal QA (Test Suite)] - Re: Logging with JBossTestCase

rachmatowicz@jboss.com do-not-reply at jboss.com
Wed Nov 15 15:25:16 EST 2006


An example of the problem is if you want to write to the log from a test case constructor for some reason. The class below subclasses from JBossTestCase:

   public MessageBodyUnitTestCase(String name) throws Exception
   {
      super(name);
      // this should return null
      log = getLog();
      if (log == null)
          System.out.println("MessageBodyUnitTestCase: null returned") ;
   }

   protected void setUp() throws Exception
   {
       // call setUp() in the superclass
       super.setUp() ;
      connect();
   }

   protected void tearDown() throws Exception
   {
      disconnect();
      // call tearDown() in the superclass to cleanup
      super.tearDown() ;
   }

The test execution shows that the log is not correctly initialsed by the time the construtor gets executed:
  
    java.lang.NullPointerException
        at org.jboss.test.jbossmessaging.test.MessageBodyUnitTestCase.connect(MessageBodyUnitTestCase.java:95)
        at org.jboss.test.jbossmessaging.test.MessageBodyUnitTestCase.setUp(MessageBodyUnitTestCase.java:82)
        at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
        at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
        at junit.extensions.TestSetup.run(TestSetup.java:23)

  
  <system-out><![CDATA[MessageBodyUnitTestCase: null returned
MessageBodyUnitTestCase: null returned

This state of affairs also holds for JBossTestCase's constructor as well - so the exception handling code won't work in initDelegate.  

But i'll change the logging arrange,ent to call getLog() when a log reference is needed, and put any once-per-test-suite stuff in a JBossTestSetup wrapper.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3986290#3986290

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3986290



More information about the jboss-dev-forums mailing list