簡體   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