c# - 你如何使用 ShouldThrow

标签 c# unit-testing testing assertions

我觉得应该是

Should.Throw<ArgumentNullException>(module.Execute(badArgument));

但是当我尝试在 Should 类或命名空间上没有 Throw 方法时。

但是有几个方法,但是当我调用 ShouldThrow 时

Should.ActionAssertionExtensions
    .ShouldThrow<ArgumentNullException>(() => module.Execute(badArgument));

它说这是一个不明确的调用,因为有两个 ShouldThrow 方法签名

void ShouldThrow<TException>(this Should.Core.Assertions.Assert.ThrowsDelegate)    
void ShouldThrow<TException>(this System.Action)

最佳答案

应该使用:

Action action = () => module.Execute(badArgument);    
action.ShouldThrow<ArgumentNullException>();

这些是在断言对象上调用的扩展方法。

关于c# - 你如何使用 ShouldThrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989852/

相关文章:

c# - .NET Core RC2 - NeutralResourcesLanguageAttribute

c# - 关于修改 NetTiers 的建议

python - 使用 Python 执行 "mini-dsl"的选项?

testing - Visual Studio 2012 vstest : run tests that do not belong to a category

ruby-on-rails - 如果我已经有一个没有任何测试的大型代码库,如何开始编写测试?

c# - 将 Rhinoscriptsyntax 从 Python 移植到 C#

c# - 使用 NUnit 尽早初始化 log4Net

php - 使用 Laravel 进行正确的测试流程?

angularjs - 单元测试 $mdDialog Angular Material

c# - 调试 Silverlight 和 Silverlight 单元测试