How to handle exceptions thrown by Tasks in xUnit .net's Assert.Throws<T>?
问题 The following asynchronous xUnit.net test with a lambda marked with the async modifier fails by reporting that no exception was thrown: [Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(async () => await sut.SearchAsync(null, dummyToken)); // Teardown } To make sure that an ArgumentNullException is actually thrown I explicitly used a