Mock objects, nUnit, call log and log4net

会有一股神秘感。 提交于 2019-12-24 19:35:53

问题


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:


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.



来源:https://stackoverflow.com/questions/252923/mock-objects-nunit-call-log-and-log4net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!