c# - 断言 xunit 中存在文件的惯用方法是什么?

标签 c# xunit

我需要断言 XUnit 单元测试中存在文件。我不想使用通用的 Assert.True(File.Exists(...)); 断言。在 NUnit 中,我们有 FileAssert.Exists。我们应该如何在 XUnit 中做到这一点?

最佳答案

一切都取决于风格偏好,但有些选项是:

  1. 像你说的那样使用断言
  2. 创建您自己的 FileAssert 帮助器类
  3. 使用流畅的断言 ( https://fluentassertions.com/ )

我个人更倾向于 FluentAssertions,所以在这个例子中它将是:

File.Exists("foo.txt").Should().BeTrue();

关于c# - 断言 xunit 中存在文件的惯用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73328952/

相关文章:

c# - 在 C# 中获得更快的 Ping 结果

c# - 单元测试 C# 属性

dependency-injection - 在 xunit 中实例化 IOptions<>

c# - 我如何使用 xUnit Assert.RaisesAny?

visual-studio-2015 - Visual Studio 2015 测试资源管理器看不到 XUnit dnx 特征

c# - 设置响应 ContentType 的中间件

c# - 在 Azure 中运行时使用自定义范围时 DefaultAzureCredential().GetTokenAsync 失败

c# - .NET 4 ObjectCache - 我们可以连接到 "Cache Expired"事件吗?

c# - C#中的线程中止

.net - Bitbucket 管道 .NET Core 测试输出