2

I am currently setting up a CI pipeline in Azure DevOps. In this pipeline, I would like to run all Tests found in the solution.

However, the pipeline fails at the test step with the following error:

A total of 81 test files matched the specified pattern.
##[error]An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
##[error]Stack trace:
##[error]   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.PlatformServiceProvider.get_AdapterTraceLogger()
##[error]   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass48_0.<RunTestInternalWithExecutors>b__0()
##[error]   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0()
##[error]--- End of stack trace from previous location where exception was thrown ---
##[error]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
##[error]   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion)
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInSTAThread(Action action, Boolean waitForCompletion)
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
##[error]Inner exception: Strong name validation failed. (Exception from HRESULT: 0x8013141A)

I find it interesting that it is not able to load the assembly Microsoft.VisualStudio.TestPlatform, because I have not referenced it anywhere. The references I do have are the following:

<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

The test task is configured like this:

steps:
- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     **\$(BuildConfiguration)\**\*test*.dll
     !**\obj\**
    runTestsInIsolation: true
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

Here is an overview of the pipeline: enter image description here

Theodor349
  • 133
  • 2
  • 15

1 Answers1

2

So, after some digging around I got it to work.

I changed the pipeline to use the .Net Core Tasks instead of Visual Studio Builds. And then it just worked.

Here is an overview of the Test par of the new pipeline: enter image description here

And here is the Yaml for the Test task:

steps:
- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '$(Parameters.TestProjects)'
    arguments: '--configuration $(BuildConfiguration)'
Theodor349
  • 133
  • 2
  • 15