logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "chenone" <one.c...@alcatel.com.cn>
Subject Re: Using Log 4 J statementin JUnit
Date Mon, 03 Dec 2001 03:39:06 GMT
Hi

I don't know how you create a instance of category and how to insert the
write log statement in your code.Pls tell me the detail information.

B.R.
chenyi
----- Original Message -----
From: <christopher.berry@etrade.com>
To: <log4j-user@jakarta.apache.org>
Sent: Monday, December 03, 2001 11:14 AM
Subject: RE: Using Log 4 J statementin JUnit


Try using a member or local variable instead of a static for log. This fixed
the problems I was having...
Cheers,
-- Chris

 -----Original Message-----
 From: Thomas SMETS [mailto:tsmets@altern.org]
 Sent: Sunday, December 02, 2001 7:32 AM
 To: log4j-user@jakarta.apache.org; junit@yahoogroups.com
 Subject: Using Log 4 J statementin JUnit



 Hi,

 I'm using Junit to functionnaly test my classes & composant behavior.
 I'm willing in the TestCase s to have some logging statements
 via Log4J.

 Classes have the typical structure : see @ the bottom.

 The TestAll class simply adds in its TestSuite, all the tests from the
 classes in the package but the main of TestAll.java containts the
 following line :
 <pre>
    public static void main(String[] args)
    {
      PropertyConfigurator.configure (PROPERTY_FILE_NAME);
      junit.swingui.TestRunner.run (TestAll.class);
    }
 </pre>

 Unfortunately the Tested classes cannot use the Appender
 defined in the
 Property-file. Could someone give me a nice & elegant way to have the
 Log4J working with JUnit tests ?

 Tx,

 Thomas,



 <pre>
 package suncertify.enhenceddb.test;

 import org.apache.log4j.*;
 import junit.framework.*;

 // Import of the class to test only
 import suncertify.enhenceddb.DatabaseException;

 /**
    *
    */
 public class TestDatabaseException
    extends TestCase
 {

    private static Logger log = Logger.getLogger
 (TestDatabaseException.class);

    private DatabaseException DBe = null;

    public TestDatabaseException(String aTestName)
    {
      super(aTestName);
    }


 /**
    * Preparation of the <code>TestCase</code>.
    */
    public void setUp()
    {
      return;
    }

 /**
    *
    */
    public void createDatabaseException()
    {
      DBe = new DatabaseException ();
      assertNotNull ( "Could not create an Exception of type
 DatabaseException",
                      DBe);
    }


 /**
    *
    */
    public void createAndThrowDatabaseException()
    {
      try
      {
        DBe = new DatabaseException ();
        throw DBe;

      } catch(DatabaseException DBEe)
      {
        assertNotNull(  "Exception of type DatabaseException thrown but
 apparently null",
                        DBEe);
      }
    }

 /**
    *
    */
    public static TestSuite suite()
    {
      TestSuite suite = new TestSuite();
        log.info ("TestSuite created");
        suite.addTest (new TestDatabaseException
 ("createDatabaseException"));
        log.info ("createDatabaseException");
        suite.addTest (new TestDatabaseException
 ("createAndThrowDatabaseException"));
        log.info ("createAndThrowDatabaseException");
      return suite;
    }

 /**
    * Dereferencing of the <code>TestCase</code>.
    */
    public void tearDown()
    {
      DBe = null;
      return;
    }


 /**
    * This main method simply calls upon the TestCase.
    *
    * @param args The classical String-array a main method accepts.
    * @return -
    */
    public static void main(String[] args)
    {
      BasicConfigurator.configure ();
      junit.swingui.TestRunner.run (TestDatabaseException.class);
    }
 }

 </pre>




 --


 rue J. Wytsman 62
 B - 1050 Brussels
 Belgium
 Tel. : +32 (0)2 742 05 94 (GMT+1)
 yahoo-id : smetsthomas



 --
 To unsubscribe, e-mail:
<mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message