What happened to Assert.DoesNotThrowAsync() in xUnit?
Solution 1:
I just wanted to update the answer with current information (Sep 2019).
As Malcon Heck mentioned, using the Record class is preferred. Looking at xUnit's Github, I see that a current way to check for lack of exceptions thrown is like this
[Fact]
public async Task CanDeleteAllTempFiles() {
var exception = await Record.ExceptionAsync(() => DocumentService.DeleteAllTempDocuments());
Assert.Null(exception);
}
Solution 2:
As you can see in this discussion, the recommended way to test if a method does not throw in xUnit v2 is to just call it.
In your example, that would be:
[Fact]
public async Task CanDeleteAllTempFiles() {
await DocumentService.DeleteAllTempDocuments();
}
Solution 3:
OP is asking about async, but if anyone else got here looking for non-async equivalent then:
[Fact]
public void TestConstructorDoesNotThrow()
{
var exception = Record.Exception(() => new MyClass());
Assert.Null(exception);
}