Mock objects, nUnit, call log and log4net

2019-08-27 15:02发布

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条回答
成全新的幸福
2楼-- · 2019-08-27 15:39

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.

查看更多
登录 后发表回答