Howto resolve .net test hangs on "Starting test execution, please wait..."

The solution that worked for me was to add an AssemblyInfo.cs file with the following contents:

using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

Once I did this, the tests started running in my CI builds again (in my case, Azure Pipelines).


Sometimes xUnit tests hang forever because the test runner pipeline can't handle parallel threads.

To check if that's the issue try adding xunit.runner.json file to the tests project root

  <ItemGroup>
    <None Update="xunit.runner.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

And put inside 1 thread config.

{
  "parallelizeTestCollections": true,
  "maxParallelThreads": -1
}

The versioning was a red herring and it turned out to be much simpler problem. My tests were testing Async controller methods, and my non-async tests were doing:

var result = controller.PostAsync(request).Result;

as soon as I changed the tests themselves to use the async/await pattern they worked fine:

var result = await controller.PostAsync(request);

Something that helped me diagnose the issue was using the dotnet test --verbosity d argument. When using this it was outputting some tests that were passing rather than just "Starting test execution, please wait". Interestingly every time I run the command it would execute a different number of tests before appearing to get stuck. This suggested there was perhaps some sort of thread deadlock issue which led me to the solution. I'm still unsure why the command ran fine on my local machine but not our Jenkins agent.