Well OK OK OK OK
You won ! :-))
Now the questionis when do we have to use the
    <code>
                    BasicConfigurator.resetConfiguration();
    </code>

Another Question is why do I have the IllegalAccessException with the
following codes when the class TestCaseWithLogging2 is declare the class
with the default access modifer ?
(Herman, I'll send you directly the two files in attachements in another
mail !).


<file name="TestCaseWithLogging.java">
package test.lang;

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

public class TestCaseWithLogging
  extends TestCase
{
  Category log = null;

  TestCaseWithLogging (String aTestName)
  {
    super (aTestName);
    log = Category.getInstance (TestCaseWithLogging.class);
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    log.info ("TestCaseWithLogging ( " + aTestName +  " )");
  }

  public void setUp ()
  {
    log.info ("public void setUp ()");
  }

  public void tearDown ()
  {
    log.info ("public void tearDown ()");
  }

  public void testToRun ()
  {
    log.info ("public void testToRun ()");
  }

  public void testToRun2 ()
  {
    log.info ("public void testToRun2 ()");
  }

  public static TestSuite suite ()
  {
    TestCase test = null;
    TestSuite suite = new TestSuite();
    suite.setName ("TestCaseWithLogging");
      test = new TestCaseWithLogging ("testToRun");
      suite.addTest (test);
      test = new TestCaseWithLogging ("testToRun2");
      suite.addTest (test);
      suite.addTest (TestCaseWithLogging2.suite ());

    return suite;
  }

  public static void main (String[] args)
  {
    junit.swingui.TestRunner.run (TestCaseWithLogging.class);
  }
}
</file>



<file name="TestCaseWithLogging2.java">
package test.lang;

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

class TestCaseWithLogging2
  extends TestCase
{
  public Category log = null;

  TestCaseWithLogging2 (String aTestName)
  {
    super (aTestName);
    log = Category.getInstance (TestCaseWithLogging2.class);
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    log.info ("TestCaseWithLogging2 ( " + aTestName +  " )");
  }

  public void setUp ()
  {
    log.info ("public void setUp ()");
  }

  public void tearDown ()
  {
    log.info ("public void tearDown ()");
  }

  public void testToRun ()
  {
    log.info ("public void testToRun ()");
  }

  public void testToRun2 ()
  {
    log.info ("public void testToRun2 ()");
  }

  public static TestSuite suite ()
  {
    //BasicConfigurator.configure ();
    TestCase test = null;
    TestSuite suite = new TestSuite();
    suite.setName ("TestCaseWithLogging2");
      test = new TestCaseWithLogging2 ("testToRun");
      suite.addTest (test);
      test = new TestCaseWithLogging2 ("testToRun2");
      suite.addTest (test);

    return suite;
  }
}
</file>

Thomas,




--

Thomas SMETS
rue J. Wytsmanstraat 62
1050 Brussel - Bruxelles
yahoo-id : smetsthomas
----- Original Message -----
From: "Greider, Herman J. (LNG)" <[EMAIL PROTECTED]>
To: "'Log4J Users List'" <[EMAIL PROTECTED]>
Sent: Monday, February 04, 2002 6:31 PM
Subject: RE: Log4J & JUnit


> Thomas,
>
> Here's an example:
>
> import org.apache.log4j.Category;
> import org.apache.log4j.BasicConfigurator;
>
> import junit.framework.Test;
> import junit.framework.TestSuite;
> import junit.framework.TestCase;
> import junit.framework.Assert;
>
> /**
>  * JUnit test with log4j. Note: This is 1.1.3 code.
>  */
> public class TestLog4j extends TestCase {
> public TestLog4j(String name) {
> super(name);
> }
> public static void main(String [] args) {
> junit.swingui.TestRunner.run(TestLog4j.class);
> }
> public void setUp() {
> // clear everything out
> BasicConfigurator.resetConfiguration();
>
> // You can do whatever you like -- XML config with DOMConfigurator,
> Props file
> // with PropertyConfigurator. I usually hard-code the full config
> here rather
> // than using a file to avoid problems with where the config file
> goes for
> // testing.
> BasicConfigurator.configure();
> }
> public static Test suite() {
> return new TestSuite(TestLog4j.class);
> }
> public void testError() throws Exception {
>
> // log4j 1.1.3 syntax
> Category cat = Category.getInstance(getClass().getName());
> assertNotNull("Category was null", cat);
>
> cat.error("Error string");
> }
> public void testWarn() throws Exception {
>
> // log4j 1.1.3 syntax
> Category cat = Category.getInstance(getClass().getName());
> assertNotNull("Category was null", cat);
>
> cat.warn("Warning string");
> }
> }
>
> > Could you point me where I could find more information with respect to
> your
> > proposal because I do not see what I should do !
> >
> > Rgds,
> >
> >Thomas,
> >
>
> >> Is this happening because you configure log4j in your setUp methods? If
> so,
> >> two ways to fix it.
> >>
> >> 1) Use the junit.extensions.TestSetup decorator and put your
> configuration
> >> in its setUp.
> >> 2) Call BasicConfigurator.resetConfiguration just before doing your
> >> configuration to clean up anything from previous tests.
> >>
>
> >>> Does some one uses Log4J & JUnit toghether ?
> >>> If yes, How does he /she do to avoid double loading of the Appender
when
> running the
> >>> suite() ?
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to