I made the following xUnit test which is using a HttpClient to call a status api method on a webserver.
[Fact]
public void AmIAliveTest()
{
var server =
Your Tests are broken.
xUnit needs the Task
return to be able to figure out that a test failed and more to the point, it is the handle where the exception bubbles back up to xUnit.
By having a public async void
, you have an orphaned Task
that exceptioned. The resultant exception of course isn't handled, and of course therefore blows up the entire Process. Therefore your test run stops.
You can fix it by writing all your tests like this...
[Fact]
public async Task AmIAliveTest()
{
var server = TestServer.Create();
var httpClient = server.HttpClient;
var response = await httpClient.GetAsync("/api/status");
response.StatusCode.Should().Be(HttpStatusCode.OK);
var resultString = await response.Content.ReadAsAsync();
resultString.Should().Be("I am alive!");
}