【发布时间】:2021-10-27 01:40:20
【问题描述】:
我正在使用FluentAssertions。
对于同步测试,我可以这样写:
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("foo");
对于异步测试,我这样做:
await action.Should().ThrowAsync<ArgumentNullException>();
是否有一种方便的方法也可以断言 ParamName,或者我必须通过包装在 try-catch 中手动执行它?
【问题讨论】:
-
我不熟悉这个库,但我认为它类似于
(await action.Should().ThrowAsync<ArgumentNullException>()).And.ParamName.Should().Be("foo"); -
@DavidL 是的,谢谢。
-
从FA 6.0开始你也可以使用
.WithParameterName("foo")。
标签: c# testing fluent-assertions