xUnit tests run locally but not on Azure DevOps
Asked Answered
C

1

6

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.

Cingulum answered 27/1, 2021 at 22:23 Comment(0)
M
6

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
M answered 28/1, 2021 at 5:28 Comment(1)
Thanks! This worked for me. A couple additional comments: 1) I was able to disable a separate build task for the unit test project, since the dot net task is looking for and building a *.csproj and not a *.dll. 2) I was also initially getting three test reports. All of them showed passing, but the task overall would fail. I changed the projects parameter to have the actual *.csproj filename (i.e. no filename wildcards), and this was resolved.Cingulum

© 2022 - 2024 — McMap. All rights reserved.