title: Running xUnit tests on Teamcity using async methods
body: <p>I made the following xUnit test which is using a HttpClient to call a status api method on a webserver. </p>
  
  <pre><code>[Fact]
  public void AmIAliveTest()
  {
      var server = TestServer.Create&lt;Startup&gt;();
  
      var httpClient = server.HttpClient;
      var response = httpClient.GetAsync("/api/status").Result;
  
      response.StatusCode.Should().Be(HttpStatusCode.OK);
      var resultString = response.Content.ReadAsAsync&lt;string&gt;().Result;
  
      resultString.Should().Be("I am alive!");
  }
  </code></pre>
  
  <p>This test is running fine locally. But when I commit the code and try to run the same test on the TeamCity build server, it runs forever. I even have to kill the xunit runner process because stopping the build will not stop this process.</p>
  
  <p>However when I write the test like this</p>
  
  <pre><code>[Fact]
  public async void AmIAliveTest()
  {
     var server = TestServer.Create&lt;Startup&gt;();
  
     var httpClient = server.HttpClient;
     var response = await httpClient.GetAsync("/api/status");
  
     response.StatusCode.Should().Be(HttpStatusCode.OK);
     var resultString = await response.Content.ReadAsAsync&lt;string&gt;();
  
     resultString.Should().Be("I am alive!");
  }
  </code></pre>
  
  <p>It runs fine locally and also on TeamCity. </p>
  
  <p>My concern is now that I forget to write the test like the second variant and that once in a while the teamcity build is hanging. </p>
  
  <p>Can anybody explain to me why xUnit running on the teamcity buildserver is not running the test correctly in the first place? And is there a solution for this to solve this?</p>