在Azure DevOps中运行.Net/VS测试运行器失败 [英] .Net/VS Test runner fails when running in Azure DevOps

查看:82
本文介绍了在Azure DevOps中运行.Net/VS测试运行器失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行针对.Net Framework 4.6.2的C#单元测试.

一切在本地都可以正常运行,它在构建时也可以正常运行,并且可以运行构建代理上安装的VS2019中的所有测试.

但是,当使用托管或自托管代理在Azure DevOps中运行生成时,即使所有测试均成功,测试步骤也会失败.

在构建代理程序上从命令行手动运行vstest.console.exe可以正常工作并成功.我使用与Azure DevOps相同的参数运行此命令.

从日志中产生的错误(数百个):

## [错误] [xUnit.net 00:00:00.0457701] Microsoft.VisualStudio.QualityTools.UnitTestFramework:灾难性故障:System.TypeInitializationException:'Xunit.DiaSession'的类型初始值设定项引发了异常. ---> System.IO.FileNotFoundException:无法加载文件或程序集'System.Reflection.TypeExtensions,版本= 4.1.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.系统找不到指定的文件.

## [错误],位于Xunit.DiaSession..cctor() ## [错误] ---内部异常堆栈跟踪的结尾--- X#.DiaSession..ctor处的## [错误](字符串assemblyFileName) 在C:\ projects \ xunit \ src \ xunit.runner.utility \ Utility \ DiaSessionWrapper_DotNet.cs:第16行的Xunit.DiaSessionWrapper..ctor(String assemblyFilename)处## [错误] 在C:\ projects \ xunit \ src \ xunit.runner中的Xunit.XunitFrontController..ctor(AppDomainSupport appDomainSupport,字符串assemblyFileName,字符串configFileName,布尔shadowCopy,字符串shadowCopyFolder,ISourceInformationProvider sourceInformationProvider,IMessageSink diagnosticMessageSink)上的

## [错误] .utility \ Frameworks \ XunitFrontController.cs:第64行

在C:\ projects \ xunit \ src中的Xunit.Runner.VisualStudio.TestStudio.TestAdapter. .runner.visualstudio \ VsTestRunner.cs:第458行

构建摘要

总测验:3679 通过:3675 跳过:4 总时间:3.4993分钟 Vstest.console.exe退出,代码为1.

在日志顶部,测试步骤初始化期间:

找到相同扩展名的多个版本.选择最高版本. Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter:14.0.2505.1 xunit.runner.visualstudio.dotnetcore.testadapter:99.99.99.0 xunit.runner.visualstudio.testadapter:99.99.99.0

管道

pool:
  name: Dedicated VS2017
  demands:
  - msbuild
  - visualstudio
  - vstest

steps:
- task: gittools.gitversion.gitversion-task.GitVersion@3
  displayName: GitVersion
  inputs:
    updateAssemblyInfo: true

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.3.0'

- task: NuGetCommand@2
  displayName: 'NuGet restore Shamrock.Web'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: Npm@1
  displayName: 'npm install Documenta'
  inputs:
    workingDir: src/Documenta/Documenta.Web/ClientApp
    verbose: false
  enabled: false

- task: Npm@1
  displayName: 'npm build Documenta/ClientApp'
  inputs:
    command: custom
    workingDir: src/Documenta/Documenta.Web/ClientApp
    verbose: false
    customCommand: 'run build'
  enabled: false

- task: Npm@1
  displayName: 'npm install Shamrock.Web/Angular'
  inputs:
    workingDir: src/Shamrock.Web/Shamrock.Web/Angular
    verbose: false
  enabled: false

- task: Npm@1
  displayName: 'npm build Shamrock.Web/Angular'
  inputs:
    command: custom
    workingDir: src/Shamrock.Web/Shamrock.Web/Angular
    verbose: false
    customCommand: 'run build'
  enabled: false

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: src/Shamrock.Web/Shamrock.Web.sln
    msbuildArgs: '/p:SEPrecompilerIncludeRazor=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true
    maximumCpuCount: true

- task: VSBuild@1
  displayName: 'Build solution D365'
  inputs:
    solution: src/Shamrock.D365/Shamrock.D365.sln
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
  enabled: false

- task: VSBuild@1
  displayName: 'Build solution Documenta'
  inputs:
    solution: src/Documenta/Documenta.sln
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
  enabled: false

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*tests.dll
     !**\obj\**
     !**\*testadapter.dll
    vsTestVersion: 16.0
    runInParallel: false
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    diagnosticsEnabled: True

- task: CopyFiles@2
  displayName: 'Copy DACPAC'
  inputs:
    Contents: '**\*.dacpac'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: CopyFiles@2
  displayName: 'Copy Database Publish Profile'
  inputs:
    Contents: '**\Shamrock.Database.publish.xml'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishSymbols@1
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
  enabled: false
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: '$(Parameters.ArtifactName)'

解决方案

仅当将在发生灾难性故障时收集高级诊断信息"标志设置为true时,才会出现此问题.

确保将其关闭,然后工作正常.

已知问题现已解决: https://developercommunity.visualstudio. com/content/problem/763234/e0434352clr-issues.html


更新2020年1月7日

即使我们前面提到的标志设置为false,这个问题仍然出现.

我们这次发现的解决方案是在管道中添加一个Tools安装程序步骤,并在测试步骤中使用它.

用户界面中的工具安装程序步骤

使用正确的测试平台版本

I'm running C# unit tests targeting .Net Framework 4.6.2.

Things are working fine locally, and it also works fine build and running all tests from VS2019 installed on the build agent.

But when running a build in Azure DevOps, using either hosted or self hosted agent, test step fails even though all tests are successful.

Running vstest.console.exe manually from command line, on the build agent, works fine and succeeds. I run this command with the same parameters as done by Azure DevOps.

Error produced from the log (hundreds of them):

##[error][xUnit.net 00:00:00.0457701] Microsoft.VisualStudio.QualityTools.UnitTestFramework: Catastrophic failure: System.TypeInitializationException: The type initializer for 'Xunit.DiaSession' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

##[error] at Xunit.DiaSession..cctor() ##[error] --- End of inner exception stack trace --- ##[error] at Xunit.DiaSession..ctor(String assemblyFileName) ##[error] at Xunit.DiaSessionWrapper..ctor(String assemblyFilename) in C:\projects\xunit\src\xunit.runner.utility\Utility\DiaSessionWrapper_DotNet.cs:line 16

##[error] at Xunit.XunitFrontController..ctor(AppDomainSupport appDomainSupport, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink) in C:\projects\xunit\src\xunit.runner.utility\Frameworks\XunitFrontController.cs:line 64

##[error] at Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner.RunTestsInAssembly(IRunContext runContext, IFrameworkHandle frameworkHandle, LoggerHelper logger, TestPlatformContext testPlatformContext, IMessageSinkWithTypes reporterMessageHandler, AssemblyRunInfo runInfo) in C:\projects\xunit\src\xunit.runner.visualstudio\VsTestRunner.cs:line 458

Build summary

Total tests: 3679 Passed: 3675 Skipped: 4 Total time: 3.4993 Minutes Vstest.console.exe exited with code 1.

At the top of the log, during initialization of test step:

Multiple versions of same extension found. Selecting the highest version. Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter : 14.0.2505.1 xunit.runner.visualstudio.dotnetcore.testadapter : 99.99.99.0 xunit.runner.visualstudio.testadapter : 99.99.99.0

Pipeline

pool:
  name: Dedicated VS2017
  demands:
  - msbuild
  - visualstudio
  - vstest

steps:
- task: gittools.gitversion.gitversion-task.GitVersion@3
  displayName: GitVersion
  inputs:
    updateAssemblyInfo: true

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.3.0'

- task: NuGetCommand@2
  displayName: 'NuGet restore Shamrock.Web'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: Npm@1
  displayName: 'npm install Documenta'
  inputs:
    workingDir: src/Documenta/Documenta.Web/ClientApp
    verbose: false
  enabled: false

- task: Npm@1
  displayName: 'npm build Documenta/ClientApp'
  inputs:
    command: custom
    workingDir: src/Documenta/Documenta.Web/ClientApp
    verbose: false
    customCommand: 'run build'
  enabled: false

- task: Npm@1
  displayName: 'npm install Shamrock.Web/Angular'
  inputs:
    workingDir: src/Shamrock.Web/Shamrock.Web/Angular
    verbose: false
  enabled: false

- task: Npm@1
  displayName: 'npm build Shamrock.Web/Angular'
  inputs:
    command: custom
    workingDir: src/Shamrock.Web/Shamrock.Web/Angular
    verbose: false
    customCommand: 'run build'
  enabled: false

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: src/Shamrock.Web/Shamrock.Web.sln
    msbuildArgs: '/p:SEPrecompilerIncludeRazor=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true
    maximumCpuCount: true

- task: VSBuild@1
  displayName: 'Build solution D365'
  inputs:
    solution: src/Shamrock.D365/Shamrock.D365.sln
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
  enabled: false

- task: VSBuild@1
  displayName: 'Build solution Documenta'
  inputs:
    solution: src/Documenta/Documenta.sln
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
  enabled: false

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*tests.dll
     !**\obj\**
     !**\*testadapter.dll
    vsTestVersion: 16.0
    runInParallel: false
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    diagnosticsEnabled: True

- task: CopyFiles@2
  displayName: 'Copy DACPAC'
  inputs:
    Contents: '**\*.dacpac'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: CopyFiles@2
  displayName: 'Copy Database Publish Profile'
  inputs:
    Contents: '**\Shamrock.Database.publish.xml'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishSymbols@1
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
  enabled: false
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: '$(Parameters.ArtifactName)'

解决方案

The problem occurs only when the "Collect advanced diagnostics in case of catastrophic failures" flag is set to true.

Make sure that it is off, then it works fine.

Known issue now fixed: https://developercommunity.visualstudio.com/content/problem/763234/e0434352clr-issues.html


Update 7th January, 2020

This issue showed up again, even though we had aforementioned flag set to false.

The solution we found this time was to add a Tools installer step to the pipeline, and use that from the test step.

Tools installer step in UI

Using the correct test platform version

这篇关于在Azure DevOps中运行.Net/VS测试运行器失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆