xUnit 在本地测试 运行,但不在 Azure DevOps 上测试
xUnit tests run locally but not on Azure DevOps
我有 xUnit 测试,在本地 运行 很好,但在 Azure DevOps 上没有 运行。被测程序集和测试程序集一样是 .NET 5.0 程序集。
检查 VsTest 任务的日志文件,我看到以下内容
Test run detected DLL(s) which were built for different framework and platform versions. Following DLL(s) do not match current settings, which are .NETFramework,Version=v5.0 framework and X86 platform.
UnitTests.dll is built for Framework .NETCoreApp,Version=v5.0 and Platform AnyCPU.
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CoreUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CrossPlatEngine.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.PlatformAbstractions.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Microsoft.TestPlatform.Utilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.VisualStudio.TestPlatform.Common.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.VisualStudio.TestPlatform.ObjectModel.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
testhost.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
xunit.runner.visualstudio.dotnetcore.testadapter.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
link 并没有多大帮助(也许内容已经改变)。我尝试在我的构建任务中使用命令行参数更改它:/Framework:net50 /Platform:x64(AnyCPU 似乎不是一个有效的选项。)
... 以及使用 .运行settings 文件(linked 在我的构建任务中)
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
<TargetFrameworkVersion>net50</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
... 也可以通过 link 连接到管道的 BuildPlatform。
无论这些更改如何,日志文件中的错误(以及第一句中列出的当前设置)都保持不变。
xUnit tests run locally but not on Azure DevOps
根据报错信息:
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU
您的测试项目似乎使用的是旧版 SDK。
要解决此问题,请尝试使用 dot net 测试而不是 VS 测试任务来测试 dll 文件:
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
enabled: false
我有 xUnit 测试,在本地 运行 很好,但在 Azure DevOps 上没有 运行。被测程序集和测试程序集一样是 .NET 5.0 程序集。
检查 VsTest 任务的日志文件,我看到以下内容
Test run detected DLL(s) which were built for different framework and platform versions. Following DLL(s) do not match current settings, which are .NETFramework,Version=v5.0 framework and X86 platform.
UnitTests.dll is built for Framework .NETCoreApp,Version=v5.0 and Platform AnyCPU.
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CoreUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CrossPlatEngine.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.PlatformAbstractions.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Microsoft.TestPlatform.Utilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.VisualStudio.TestPlatform.Common.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.VisualStudio.TestPlatform.ObjectModel.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
testhost.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
xunit.runner.visualstudio.dotnetcore.testadapter.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
link 并没有多大帮助(也许内容已经改变)。我尝试在我的构建任务中使用命令行参数更改它:/Framework:net50 /Platform:x64(AnyCPU 似乎不是一个有效的选项。)
... 以及使用 .运行settings 文件(linked 在我的构建任务中)
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
<TargetFrameworkVersion>net50</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
... 也可以通过 link 连接到管道的 BuildPlatform。
无论这些更改如何,日志文件中的错误(以及第一句中列出的当前设置)都保持不变。
xUnit tests run locally but not on Azure DevOps
根据报错信息:
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU
您的测试项目似乎使用的是旧版 SDK。
要解决此问题,请尝试使用 dot net 测试而不是 VS 测试任务来测试 dll 文件:
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
enabled: false