我需要断言 XUnit 单元测试中存在文件。我不想使用通用的 Assert.True(File.Exists(...));
断言。在 NUnit 中,我们有 FileAssert.Exists。我们应该如何在 XUnit 中做到这一点?
最佳答案
一切都取决于风格偏好,但有些选项是:
- 像你说的那样使用断言
- 创建您自己的 FileAssert 帮助器类
- 使用流畅的断言 ( https://fluentassertions.com/ )
我个人更倾向于 FluentAssertions,所以在这个例子中它将是:
File.Exists("foo.txt").Should().BeTrue();
关于c# - 断言 xunit 中存在文件的惯用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73328952/