views:

597

answers:

1

A very often scenario of unit test is as follows:

public void SetUp()
{
  this.callLog = new StringBuilder();
}

public void TestBuzzBar()
{
  var bar = new Bar(new MockFoo(callLog));
  bar.Buzz(17);
  Assert.AreEqual("MockFoo.Init(17) MockFoo.PrepareStuff MockFoo.DoTheJob ", callLog.ToString());
}

... with MockFoo implementing an IFoo interface by just appending strings a call log. It requires a lot of code handling with callLog in mocks.

Is it a good idea to use log4net to collect call log?

+1  A: 

To answer your question: log4net is a great logging framework. It is easy to set up and use. I have used it in unit tests with a MemoryAppender which essentially enables you to go back and peek at what have been logged during the test. This technique works for both mocks and SUT.

Peter Lillevold