You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级MSTest包后Azure Pipeline报错:找不到UnitTestRunner构造函数

解决MSTest.TestAdapter/Framework升级后Azure Pipeline测试任务失败问题

问题原因

升级MSTest.TestAdapter到3.x版本后,Azure Pipeline的VSTest@2任务默认使用的测试平台版本与新适配器不兼容,导致无法找到构造函数。本地Visual Studio自带的测试平台为最新版本,因此能正常运行。

解决方案

1. 强制VSTest任务使用最新测试平台版本

在VSTest@2任务中添加vsTestVersion: 'latest'配置,让测试运行器匹配升级后的MSTest适配器版本:

steps:
- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\*Tests.dll
     !**\obj\**
    testFiltercriteria: 'TestCategory!=IgnoreOnBuild'
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    vsTestVersion: 'latest'  # 添加此配置
  continueOnError: false

2. 确认测试项目的NuGet引用一致性

检查测试项目的.csproj文件,确保MSTest.TestAdapter和MSTest.TestFramework版本统一为3.6.3,无旧版本残留引用:

<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />

3. 清理Pipeline缓存

若上述操作无效,清理Azure Pipeline的缓存以避免旧测试组件残留:

  • 进入Pipeline编辑页面,添加Cache@2任务配置缓存清理逻辑,或在运行Pipeline时选择"Disable cache"选项重新执行。

验证

修改完成后重新运行Pipeline,测试任务应能成功执行,与本地Visual Studio运行结果一致。

内容的提问来源于stack exchange,提问作者Mandeep Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 23:52:02