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

VS 2017 15.7.1中原有MSTest单元测试无法执行问题咨询

问题描述
  • 原有在VS 2015中编写的MSTest单元测试,升级至VS 2017初期可正常运行
  • VS 2017更新后系统崩溃,重装系统并安装全新VS 2017 15.7.1后,所有测试无法执行:点击运行后测试资源管理器进度条正常滚动,但结束后仍显示“测试未运行”
  • 开启Diagnostic日志级别后,输出日志如下:
[14.05.18 15:12:50 Diagnostic] About to Enqueue operation 'RunSelectedOperation', hashcode:21607723 
[14.05.18 15:12:50 Diagnostic] Enqueue operation 'RunSelectedOperation', hashcode:21607723 
[14.05.18 15:12:50 Diagnostic] Operation left in the the queue: 1 
[14.05.18 15:12:50 Diagnostic] 'RunSelectedOperation', hashcode:21607723 
[14.05.18 15:12:50 Diagnostic] 
[14.05.18 15:12:50 Diagnostic] Processing Queue ..... 
[14.05.18 15:12:50 Diagnostic] Operation Dequeue : 'RunSelectedOperation' 
[14.05.18 15:12:50 Diagnostic] VirtualReadOnlyTestDataStore.OperationStateChanged State=OperationSetStarted, operationInProgress=False 
[14.05.18 15:12:50 Diagnostic] TestDiscoveryStats.OperationStateChanged State=OperationSetStarted, InProgress=False 
[14.05.18 15:12:50 Diagnostic] VirtualReadOnlyTestDataStore.OperationStateChanged State=ChangeDetectionStarting, operationInProgress=True 
[14.05.18 15:12:50 Diagnostic] TestDiscoveryStats.OperationStateChanged State=ChangeDetectionStarting, InProgress=False 
[14.05.18 15:12:50 Diagnostic] We programmatically start the build in TestWindowHost.UpdateContainer... 
[14.05.18 15:12:50 Diagnostic] After we await the build that programmatically started in TestWindowHost.UpdateContainer... 
[14.05.18 15:12:50 Diagnostic] TestContainer update (build) complete : 266 ms 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid 098d9992-63a7-41c5-b5b3-6ce5e783f868 
[14.05.18 15:12:50 Diagnostic] Time taken for fetching Roslyn supported projects: 0 milliseconds. 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid 1e96f94e-161d-41eb-8546-edd8cd13aff4 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid 3a39b466-3d4f-4a0c-b110-f045d0975713 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid 69c4cbe6-5541-45ac-8d23-852bce725f99 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid 1b84143e-3826-4937-8073-0d2a9b89982a 
[14.05.18 15:12:50 Diagnostic] Adding the Project in Project Map for Guid e30be865-289f-4f78-8d26-9fd1802cf87b 
[14.05.18 15:12:51 Diagnostic] Adding the Project in Project Map for Guid 79f803ca-528e-419f-92e8-d9df4c5624d0 
[14.05.18 15:12:51 Diagnostic] Adding the Project in Project Map for Guid fe6a60de-81f3-4f58-bb72-47956957e916 
[14.05.18 15:12:51 Diagnostic] Adding the Project in Project Map for Guid 36f10149-4d39-47f5-924f-726b36f30b83 
[14.05.18 15:12:51 Diagnostic] test container discoverer executor://vsprojectoutputcontainerdiscoverer/v1, discovered 8 containers 
[14.05.18 15:12:51 Diagnostic] Containers from 'Microsoft.VisualStudio.TestWindow.VsAdapters.VsProjectOutputContainerDiscoverer' : 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\Authentication\bin\Debug\Authentication.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\Common\bin\Debug\Common.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\FlowTests\bin\Debug\FlowTests.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\Opus3TestAutomation\bin\Debug\Opus3TestAutomation.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\OpusAutomation\bin\Debug\OpusAutomation.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\OpusResources\bin\Debug\OpusResources.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\OpusTests\bin\Debug\OpusTests.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] C:\Source\Workspaces\QA\Opus3TestAutomation\TestData\bin\Debug\TestData.dll:executor://vsprojectoutputcontainerdiscoverer/v1 
[14.05.18 15:12:51 Diagnostic] test container discoverer executor://testexplorerservicecontainerdiscoverer/v1, discovered 0 containers 
[14.05.18 15:12:51 Diagnostic] No containers found from 'Microsoft.VisualStudio.TestWindow.Extensibility
解决方案建议

从日志来看,测试容器已经被正常发现,但没有进入执行环节,给你几个实用的排查和修复步骤:

  • 更新MSTest NuGet包:打开解决方案的NuGet包管理器,检查测试项目中的Microsoft.VisualStudio.TestPlatform.TestFramework和Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions包版本,将它们更新到与VS2017 15.7.1兼容的版本(比如11.0.0或适配的更高版本)——重装VS后往往会出现包版本不匹配的问题,这是测试执行失败的常见原因。
  • 彻底清理重建项目:
    1. 关闭VS,删除所有测试项目的bin和obj文件夹
    2. 删除解决方案根目录下的.vs隐藏文件夹
    3. 重新打开VS,依次执行清理解决方案和重建解决方案
  • 用命令行执行测试:打开VS的开发者命令提示符,运行以下命令直接执行单个测试项目,获取更详细的错误信息:
    vstest.console.exe "C:\Source\Workspaces\QA\Opus3TestAutomation\Authentication\bin\Debug\Authentication.dll"
    
    如果命令行能正常执行,说明是VS测试资源管理器的UI层面问题;如果也失败,会输出具体的错误原因(比如依赖缺失、框架不兼容等)。
  • 检查测试项目目标框架:确认所有测试项目的目标.NET Framework版本在VS2017支持范围内(比如.NET Framework 4.5及以上),版本过高或过低都可能导致测试无法执行。
  • 禁用并行测试:打开测试资源管理器的设置(齿轮图标),取消勾选“Run tests in parallel”选项,旧版MSTest和并行执行功能有时会存在兼容性冲突。
  • 验证测试属性:检查所有测试类是否标记了[TestClass]属性,测试方法是否标记了[TestMethod]属性,拼写错误或缺失这些属性会导致测试无法被识别执行。
  • 升级VS2017补丁:VS2017 15.7.1存在一些已知的测试执行问题,尝试通过VS的“工具->获取工具和功能”升级到VS2017的最新补丁版本,或者回退到之前稳定的15.6.x版本试试。

内容的提问来源于stack exchange,提问作者Frank H.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:56:38