NUnit 单元测试有“ExpectedException”但仍然因异常而失败
我有一个单元测试失败,因为抛出了 System.ArgumentException
,即使我期待它并且它是故意的行为 - 我错过了什么?
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Seconds from midnight cannot be more than 86400 in 010100712386401000000012")]
public void TestParsingCustomReferenceWithInValidSecondsFromMidnight()
{
// I am expecting this method to throw an ArgumentException:
CustomReference.Parse("010100712386401000000012");
}
我也尝试过不设置 ExpectedMessage
- 没有区别。
I have a unit test that is failing because a System.ArgumentException
is being thrown, even though I am expecting it and it's deliberate behaviour - what have I missed?
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Seconds from midnight cannot be more than 86400 in 010100712386401000000012")]
public void TestParsingCustomReferenceWithInValidSecondsFromMidnight()
{
// I am expecting this method to throw an ArgumentException:
CustomReference.Parse("010100712386401000000012");
}
I've also tried without the ExpectedMessage
being set - no difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试过断言语法吗?
Have you tried the assertion syntax?
预期的消息是否正确?这与 CustomReference.Parse(string) 抛出的消息完全相同吗?例如,它不是 NUnit 控制台中显示的内容。
我不知道这行不通的另一个原因。您使用什么版本的 NUnit?
Is the expected message correct? Is that the exact same message that CustomReference.Parse(string) throws? For example, it is not what is being displayed in the NUnit console.
I wouldn't know another reason why this would not work. What version of NUnit are you using?
如果你这样做会发生什么?
What happens if you do this?