unit-testing - Howto resolve .net test hangs on "Starting test execution, please wait..."
问题描述
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
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]
As per the error message, we have installed the dotnet core SDK on the server but we seem to be missing something.
My test project looks like:
<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>
解决方案
版本控制是一个红鲱鱼,结果证明是一个简单得多的问题。我的测试正在测试异步控制器方法,而我的非异步测试正在执行:
var result = controller.PostAsync(request).Result;
一旦我将测试本身更改为使用 async/await 模式,它们就可以正常工作:
var result = await controller.PostAsync(request);
帮助我诊断问题的方法是使用dotnet test --verbosity d
论点。使用它时,它会输出一些正在通过的测试,而不仅仅是“开始测试执行,请稍候”。有趣的是,每次我运行该命令时,它都会在出现卡住之前执行不同数量的测试。这表明可能存在某种线程死锁问题,导致我找到了解决方案。我仍然不确定为什么该命令在我的本地机器上运行良好,但不是我们的 Jenkins 代理。
推荐阅读
- gstreamer - 您如何找出 gstreamer 配置文件字符串
- android - 如何确定为我的 Android 应用程序设置哪个 minSDKVersion
- c - 如何运行用c编写的jpegs恢复程序?
- join - 计算分组在第三个表下的两个不同表中的行数
- google-sheets - 将谷歌图纸添加到不受保护的范围?
- maps - 除了android api中的屏幕截图之外,还有其他获取可打印数据的选项吗?
- c - 有充分的理由为什么在 C 中必须将 * 放在每个指针变量之前?
- neo4j - neo4j 在尝试协调数据库时遇到错误
- php - 当 curl 和 Postman 完全正常时,Guzzle 错误“调用 null 时的成员函数 getStatusCode()”
- java - 如何将数据从活动传递到android中的回收器视图适配器