模拟对象、nUnit、调用日志和 log4net
单元测试的一个常见场景如下:
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());
}
... MockFoo 通过仅将字符串附加到调用日志来实现 IFoo 接口。 它需要在模拟中使用 callLog 进行大量代码处理。
使用 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答你的问题:log4net 是一个很棒的日志框架。 它易于设置和使用。 我在单元测试中使用了 MemoryAppender,它本质上使您能够返回并查看测试期间记录的内容。 该技术适用于模拟和 SUT。
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.