繁体   English   中英

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

[英]What is the idiomatic way to assert that a file exists in xunit?

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

没有惯用的方法来进行文件存在检查。 只需按照您的预期使用 File.Exists 断言 true 。 xunit 文档在描述 API 的建议用法方面做得很差,但是您可以浏览xunit 存储库中的断言命名空间,并看到不存在特定于文件的断言。

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

  1. 像你说的那样使用 Assert
  2. 创建您自己的 FileAssert 助手 class
  3. 使用 FluentValidations ( https://fluentassertions.com/ )

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM