xUnit 测试在本地运行,但不在 Azure DevOps 上运行

2024-04-21

我的 xUnit 测试在本地运行良好,但无法在 Azure DevOps 上运行。受测试的程序集是 .NET 5.0 程序集,测试程序集也是如此。

检查 VsTest 任务的日志文件,我看到以下内容

测试运行检测到针对不同框架和平台版本构建的 DLL。以下 DLL 与当前设置不匹配,即 .NETFramework、Version=v5.0 框架和 X86 平台。

UnitTests.dll 是为 Framework .NETCoreApp、Version=v5.0 和 Platform AnyCPU 构建的。

Microsoft.TestPlatform.CommunicationUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

Microsoft.TestPlatform.CoreUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

Microsoft.TestPlatform.CrossPlatEngine.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

Microsoft.TestPlatform.PlatformAbstractions.dll 是为 Framework .NETCoreApp、Version=v2.1 和 Platform AnyCPU 构建的。

Microsoft.TestPlatform.Utilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

Microsoft.VisualStudio.TestPlatform.Common.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

Microsoft.VisualStudio.TestPlatform.ObjectModel.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。

testhost.dll 是为 Framework .NETCoreApp、Version=v2.1 和 Platform AnyCPU 构建的。

xunit.runner.visualstudio.dotnetcore.testadapter.dll 是为 Framework .NETCoreApp、Version=v2.1 和 Platform AnyCPU 构建的。

Go to 有关管理这些设置的更多详细信息。

该链接并没有多大帮助(也许内容已更改)。我尝试在构建任务中使用命令行参数更改此设置: /Framework:net50 /Platform:x64 (AnyCPU 似乎不是有效的选项。)

...以及使用 .runsettings 文件(链接在我的构建任务中)

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <TargetPlatform>x64</TargetPlatform>
    <TargetFrameworkVersion>net50</TargetFrameworkVersion>
  </RunConfiguration>
</RunSettings>

...以及链接到管道的 BuildPlatform。

无论进行任何这些更改,日志文件中的错误(以及第一句中列出的当前设置)都保持不变。


xUnit 测试在本地运行,但不在 Azure DevOps 上运行

根据错误信息:

Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU

您的测试项目似乎使用旧的 SDK。

要解决此问题,请尝试使用 dot net test 而不是 VS test 任务来测试 dll 文件:

- task: DotNetCoreCLI@2

  displayName: Test

  inputs:

    command: test

    projects: '**/*[Tt]ests/*.csproj'

    arguments: '--configuration $(BuildConfiguration)'

  enabled: false
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

xUnit 测试在本地运行,但不在 Azure DevOps 上运行 的相关文章

随机推荐