【问题标题】:DevOps Test Assemblies: Could not load file or assemblyDevOps 测试程序集:无法加载文件或程序集
【发布时间】:2021-07-22 12:51:10
【问题描述】:

我目前正在 Azure DevOps 中设置 CI 管道。 在这个管道中,我想运行解决方案中的所有测试。

但是,管道在测试步骤失败并出现以下错误:

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)

我发现它无法加载程序集Microsoft.VisualStudio.TestPlatform 很有趣,因为我没有在任何地方引用它。 我的参考资料如下:

<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>

测试任务是这样配置的:

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

以下是管道概览:

【问题讨论】:

  • 您是否在此构建之前恢复了您的 nuget 包?
  • @subhankars 是的,我现在添加了管道本身的概述。

标签: .net unit-testing testing azure-devops pipeline


【解决方案1】:

所以,经过一番挖掘,我让它工作了。

我更改了管道以使用 .Net Core Tasks 而不是 Visual Studio Builds。然后它就起作用了。

以下是新管道的测试部分的概述:

这是测试任务的 Yaml:

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

【讨论】:

  • 您应该提到您正在测试一个 .net 核心应用程序。很高兴它对你有用。
  • 是的,我只用标签 .Net 而不是 .Net Core 来标记它。我的错误
猜你喜欢
  • 2013-03-22
  • 2013-06-18
  • 2017-12-09
  • 2023-01-17
  • 2020-08-17
相关资源
最近更新 更多