首页 > 解决方案 > 我正在为我的测试项目使用 MStest (.net core),有没有办法在失败时继续执行测试?

问题描述

我希望我的测试在断言失败后继续下一行。我试过“try catch block”,但测试没有失败。我们有什么可以在流利的断言 [https://fluentassertions.com/] 中解决这个问题的方法,或者无论如何在代码中处理这个问题?

标签: mstestfluent-assertions

解决方案


听起来你正在寻找 FluentAssertions 的AssertionScope

using (new AssertionScope())
{
    5.Should().Be(10); // will fail but not throw
    DoSomeOtherStuff();
} // assertion will raise exception

所有失败的断言将被收集,直到AssertionScope被处理。


推荐阅读