如何包含内部方法
我不想使用 [ExpectedException(ExceptionType = typeof(Exception), ExpectedMessage = "")] 而想将异常包含在我的方法中。我可以这样做吗?请举个例子。
谢谢
I don`t want to use the [ExpectedException(ExceptionType = typeof(Exception), ExpectedMessage = "")] instead would like to include the exception inside my method. Can I do that? Any example please.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有时我想测试特定异常属性的值,在这种情况下,我有时选择不使用 ExpectedException 属性。
相反,我使用以下方法(示例):
Sometimes I want to test for the value of particular exception properties and in that case I sometimes choose to not use the ExpectedException attribute.
Instead I use the following approach (an example):
你的问题不太有意义。直觉上,我猜您是在问让单元测试中捕获异常,然后即使异常已引发,您也可以执行断言?
编辑:
或者
Your question doesn't quite make sense. As a hunch, I guess you're asking about letting an exception be caught in your unit test, and then you can perform an assertion even though the exception has been raised?
EDIT:
Or
像这样的东西:
something like this: