You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Thibaut Barrère <th...@gmail.com> on 2005/04/27 20:29:21 UTC

A mock log4net appender

Hi,

I wrote a mock log4net appender to ensure that my unit tests fails when
some errors are (sometimes silently) logged through log4net.

Sample usage in NUnit style:

[SetUp]
public void SetUp()
{
       DOMConfigurator.Configure();

       // create a mock log4net appender to verify that no error is outputted
       mockLog4netAppender = new MockLog4netAppender();
       // expect zero errors
       mockLog4netAppender.ExpectErrors(0);
       mockLog4netAppender.RegisterAppender();
}

[TearDown]
public void TearDown()
{
       // verify that no error was outputed by log4net
       mockLog4netAppender.Verify();
}


Current implementation is very basic, and depends upon NMock; it's
actually a specialized DynamicMock, so specific expectations can be
added in each test when required.

Is there some interest for including tools of this kind in the log4net
distribution (either as a static mock, or a dynamic mock) ? Or is
there an already available feature which could provide the same
service ?


best regards

Thibaut Barrère

http://www.dotnetguru2.org/tbarrere

Re: A mock log4net appender

Posted by Owen Corpening <oc...@acornsys.com>.
that would be super!

"Thibaut Barr�re" <th...@gmail.com> wrote in message
news:4a68b8cf05042711297cd2165f@mail.gmail.com...
Hi,

I wrote a mock log4net appender to ensure that my unit tests fails when
some errors are (sometimes silently) logged through log4net.

Sample usage in NUnit style:

[SetUp]
public void SetUp()
{
       DOMConfigurator.Configure();

       // create a mock log4net appender to verify that no error is
outputted
       mockLog4netAppender = new MockLog4netAppender();
       // expect zero errors
       mockLog4netAppender.ExpectErrors(0);
       mockLog4netAppender.RegisterAppender();
}

[TearDown]
public void TearDown()
{
       // verify that no error was outputed by log4net
       mockLog4netAppender.Verify();
}


Current implementation is very basic, and depends upon NMock; it's
actually a specialized DynamicMock, so specific expectations can be
added in each test when required.

Is there some interest for including tools of this kind in the log4net
distribution (either as a static mock, or a dynamic mock) ? Or is
there an already available feature which could provide the same
service ?


best regards

Thibaut Barr�re

http://www.dotnetguru2.org/tbarrere