I performed the following xUnit test, which uses the HttpClient to call the state api method on the web server.
[Fact] public void AmIAliveTest() { var server = TestServer.Create<Startup>(); var httpClient = server.HttpClient; var response = httpClient.GetAsync("/api/status").Result; response.StatusCode.Should().Be(HttpStatusCode.OK); var resultString = response.Content.ReadAsAsync<string>().Result; resultString.Should().Be("I am alive!"); }
This test works fine locally. But when I pass the code and try to run the same test on the TeamCity build server, it works forever. I even need to kill the xunit runner process because stopping the build will not stop this process.
However, when I write a test like this
[Fact] public async void AmIAliveTest() { var server = TestServer.Create<Startup>(); var httpClient = server.HttpClient; var response = await httpClient.GetAsync("/api/status"); response.StatusCode.Should().Be(HttpStatusCode.OK); var resultString = await response.Content.ReadAsAsync<string>(); resultString.Should().Be("I am alive!"); }
It works great locally as well as in TeamCity.
Now I'm worried that I forgot to write a test as a second option, and from time to time the teamcity build hangs.
Can someone explain to me why xUnit running on the teamcity build server does not run the test correctly in the first place? And is there a solution for this to solve this?
source share