如何解析.net测试挂起“正在开始执行测试,请稍候..." [英] Howto resolve .net test hangs on "Starting test execution, please wait..."

查看:122
本文介绍了如何解析.net测试挂起“正在开始执行测试,请稍候..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Jenkins构建服务器上的命令行执行dotnet test,但是它只是挂起了:

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

在本地运行此命令时效果很好

It works fine when running this command locally

如果我切换为使用dotnet xunit,则会失败,并显示以下内容:

If I switch to using dotnet xunit it fails with the following:

15:42:57 Locating binaries for framework netcoreapp2.1...
15:42:58 Running .NET Core 2.1 tests for framework netcoreapp2.1...
15:42:58 The specified framework version '2.1' could not be parsed
15:42:58 The specified framework 'Microsoft.NETCore.App', version '2.1' was not found.
15:42:58   - Check application dependencies and target a framework version installed at:
15:42:58       C:\Program Files\dotnet\
15:42:58   - Installing .NET Core prerequisites might help resolve this problem:
15:42:58       http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
15:42:58   - The .NET Core framework and SDK can be installed from:
15:42:58       https://aka.ms/dotnet-download
15:42:58   - The following versions are installed:
15:42:58       2.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58       2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58       2.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58       2.1.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58       2.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

根据错误消息,我们已经在服务器上安装了dotnet core SDK,但似乎缺少了一些东西.

As per the error message, we have installed the dotnet core SDK on the server but we seem to be missing something.

我的测试项目如下:

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>    
    <IsPackable>false</IsPackable>
  </PropertyGroup>    
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
    <PackageReference Include="Moq" Version="4.10.0" />
    <PackageReference Include="RichardSzalay.MockHttp" Version="5.0.0" />
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.console" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
  </ItemGroup>        
</Project>

推荐答案

版本控制是一个红色的鲱鱼,事实证明这是一个更简单的问题.我的测试正在测试异步控制器方法,而我的非异步测试正在执行:

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

使用dotnet test --verbosity d参数可以帮助我诊断问题.使用此功能时,它输出的是通过的某些测试,而不仅仅是正在开始执行测试,请稍候".有趣的是,每次我运行该命令时,它都会执行不同数量的测试,然后再出现卡住的情况.这表明可能存在某种线程死锁问题,导致我找到了解决方案.我仍然不确定为什么该命令在我的本地计算机上能正常运行,但在我们的Jenkins从机上却不能运行.

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.

这篇关于如何解析.net测试挂起“正在开始执行测试,请稍候..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆