如何构建单元测试
我有自定义事件记录器,我想测试它。
[Test]
public void AddLogWithExceptionAndEventLogEntryTypeTest()
{
const string loggerName = "mockLoggerName";
var logger = new MyLogger(loggerName);
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog("System");
string logValue = Guid.NewGuid().ToString();
logger.AddEntry(new Exception(logValue),EventLogEntryType.Error );
foreach (
EventLogEntry entry in log.Entries)
{
if (entry.Message.ToUpper().Contains(logValue))
{
//what can is do ?
}
}
}
使用什么断言来提供信息,添加了该条目?
I have custom event logger, and I want to test it.
[Test]
public void AddLogWithExceptionAndEventLogEntryTypeTest()
{
const string loggerName = "mockLoggerName";
var logger = new MyLogger(loggerName);
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog("System");
string logValue = Guid.NewGuid().ToString();
logger.AddEntry(new Exception(logValue),EventLogEntryType.Error );
foreach (
EventLogEntry entry in log.Entries)
{
if (entry.Message.ToUpper().Contains(logValue))
{
//what can is do ?
}
}
}
What assert to use to give information, that entry was added ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否打算在日志中查找刚刚添加的文本?那么怎么样:
就个人而言,我可能会模拟记录器,并断言模拟记录器的方法按预期调用。
Is your intent to look through the log for text you just added? Then how about:
Personally, I would instead probably mock the logger, and instead assert that the methods of the mocked logger were called as expected.