我正在为Visual Studio 2017开发一个自定义测试适配器。如何配置Visual Studio来调试测试适配器而不必使用hack,例如在我的适配器代码中添加Debugger.Launch()
?
答案 0 :(得分:1)
安装由Microsoft员工创建的Microsoft Child Process Debugging Power Tool。这允许您配置Visual Studio调试器以附加到子进程(这是vstest.console.exe执行测试的方式)
安装完成后,打开解决方案并启用子进程调试:
1)转到以下Visual Studio菜单位置的子进程调试设置:Debug -> Other Debug Targets -> Child Process Debugging Settings...
2)启用子进程调试:true
和Save
3)可选择使用下拉列表保持设置,以便可以将此设置检入源控件
如果您选择保留设置,则您的设置文件可能如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!-- EngineFilter Guid was found here: https://blogs.msdn.microsoft.com/martintracy/2006/05/16/debug-engine-guids/ -->
<ChildProcessDebuggingSettings IsEnabled="true" xmlns="http://schemas.microsoft.com/vstudio/ChildProcessDebuggingSettings/2014">
<DefaultRule Attach="false" />
<Rule IsEnabled="true" ProcessName="TE.ProcessHost.Managed.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.discoveryengine.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.discoveryengine.x86.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.executionengine.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.executionengine.x86.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
</ChildProcessDebuggingSettings>
设置完成后,您只需确保将项目设置为使用vstest.console.exe进行调试。这里的关键点是确保启用本机/非托管调试,否则子进程调试工具将无法工作。
编辑或创建launchSettings.json
文件,看起来与此类似:
{
"profiles": {
"DebugTestAdapter": {
"commandName": "Executable",
"executablePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe",
"commandLineArgs": "Tests.dll --ListTests --TestAdapterPath:.",
"workingDirectory": "C:\\Projects\\TestAdapter\\Tests\\bin\\Debug\\net46"
}
}
}
修改csproj文件以包含以下属性,该属性启用了本机调试:
<PropertyGroup>
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
</PropertyGroup>
在项目的调试属性页面中,设置以下设置:
启动外部程序:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
命令行参数:
Tests.dll --ListTests --TestAdapterPath:.
工作目录:
C:\Projects\TestAdapter\Tests\bin\Debug
启用本机代码调试:
将此值设置为true