NUnit的:测试,没有预期的异常 [英] NUnit: test with NO expected exception

查看:116
本文介绍了NUnit的:测试,没有预期的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建NUnit测试,以确保我的函数没有抛出异常。有没有做一些特殊的方式,或者我应该只写

  [测试] 
公共无效noExceptionTest() {
testedFunction();
}



如果没有异常被抛出它会成功吗?


解决方案

  Assert.DoesNotThrow(()=> {/ *自定义代码块这里* /}); 

或只是方法

  Assert.DoesNotThrow(()=> CallMymethod()); 

有关详细信息,请参阅的 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 just method

Assert.DoesNotThrow(() => CallMymethod());

For more details see NUnit Exception Asserts

这篇关于NUnit的:测试,没有预期的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆