【发布时间】:2022-01-10 16:04:00
【问题描述】:
我是 Xunit 的新手。我在代码中抛出了一个新异常:
throw new NotImplementedException("Missing UPC. File is corrupt");
在我的测试文件中我写道:
[Fact]
public void ParserRow_Throws_Exception_For_Null_UPC()
{
var record = GetRessoRecord();
record.UPC = "";
RevenueReportItem result = Sut.ParseRow(record);
Assert.Throws<NotImplementedException>(() => Sut.ParseRow(record));
}
测试资源管理器中的错误消息显示
System.NotImplementedException:缺少 UPC。文件已损坏
如何添加返回的报价?
【问题讨论】:
-
您调用了两次测试方法。删除断言之外的第一个调用,因为它会抛出异常并停止测试执行。
-
感谢@CeeMcSharpface。希望你在单独的答案中回答了这个问题,所以我可以证明它解决了这个问题!