I need to assert that a file exists in an XUnit unit test. I do not want to use the generic Assert.True(File.Exists(...));
assertion. In NUnit we have FileAssert.Exists
. How are we supposed to do it in XUnit?
There is no idiomatic way to do file existence checks. Just assert true using File.Exists as you expected. The xunit documentation is pretty poor about describing the API's suggested usage, but you can browse the assert namespace in the xunit repo and see that there are no file specific asserts that exist.
All depends on style preference, but some options are:
I've personally been steering more towards FluentAssertions, so in this example it would be:
File.Exists("foo.txt").Should().BeTrue();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.