测试没有预期的异常 [英] Test with NO expected exception
本文介绍了测试没有预期的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建 NUnit 测试以确保我的函数不会抛出异常.有什么具体的方法可以做到,或者我应该写
I want to create NUnit test to ensure that my function does not throw an exception. Is there some specific way to do it, or I should just write
[Test]
public void noExceptionTest() {
testedFunction();
}
如果不抛出异常会成功吗?
and it will succeed if no exception is thrown?
推荐答案
Assert.DoesNotThrow(() => { /* custom code block here*/});
OR 只是方法
Assert.DoesNotThrow(() => CallMymethod());
有关详细信息,请参阅 NUnit 异常断言
For more details see NUnit Exception Asserts
这篇关于测试没有预期的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文