Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

xUnit tests run locally but not on Azure DevOps

I have xUnit tests which run fine locally but do not get run on Azure DevOps. The assembly under test is a .NET 5.0 assembly as is the test assembly.

Examining the log file from the VsTest task, I see the following

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.

The link does not really help much (perhaps the content has changed). I have tried changing this using commandline arguments in my Build task: /Framework:net50 /Platform:x64 (AnyCPU does not seem to be a valid option.)

... and also by using a .runsettings file (linked in my build task)

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

... and also by linking to the BuildPlatform for the pipeline.

Regardless of any of these changes, the errors in the log file (and also the current settings listed in the first sentence) remain the same.

question from:https://stackoverflow.com/questions/65928305/xunit-tests-run-locally-but-not-on-azure-devops

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

xUnit tests run locally but not on Azure DevOps

According to the error message:

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

It seems you are using the old SDK for your test project.

To resolve this issue, please try to use dot net test instead of VS test task to test the dll file:

- task: DotNetCoreCLI@2

  displayName: Test

  inputs:

    command: test

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

    arguments: '--configuration $(BuildConfiguration)'

  enabled: false

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...