Howto resolve .net test hangs on “Starting test execution, please wait…”

前端 未结 4 890
感情败类
感情败类 2021-02-15 14:31

I am trying to execute dotnet test from the command line on our Jenkins build server, but it just hangs on:

Starting test execution, please wait...

相关标签:
4条回答
  • 2021-02-15 15:10

    Updating Microsoft.NET.Test.Sdk from 15.9 to 16.3 helped in csproj file.

    0 讨论(0)
  • 2021-02-15 15:23

    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
    }
    
    0 讨论(0)
  • 2021-02-15 15:35

    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).

    0 讨论(0)
  • 2021-02-15 15:36

    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 slave.

    0 讨论(0)
提交回复
热议问题