Lev
Lev

Reputation:

Mock objects, nUnit, call log and log4net

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?

Upvotes: 0

Views: 1708

Answers (1)

Peter Lillevold
Peter Lillevold

Reputation: 33930

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.

Upvotes: 1

Related Questions