Search code examples
c#xunit

What happened to Assert.DoesNotThrowAsync() in xUnit?


I migrated my unit test project from version 2.0.0-beta-{something} to 2.0.0 (stable) through NuGet. It seems like Assert.DoesNotThrowAsync() is not available anymore.

For Example:

[Fact]
public void CanDeleteAllTempFiles() {
    Assert.DoesNotThrowAsync(async () => DocumentService.DeleteAllTempDocuments());
}

Results in

DocumentServiceTests.cs(11,11): Error CS0117: 'Xunit.Assert' does not contain a definition for 'DoesNotThrowAsync' (CS0117)

A workaround would be to omit the test. Is there any better solution?


Solution

  • 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);
    }