【问题标题】:How do I debug a custom test adapter in Visual Studio如何在 Visual Studio 中调试自定义测试适配器
【发布时间】:2023-03-18 14:50:01
【问题描述】:

我正在为 Visual Studio 2017 开发自定义测试适配器。如何配置 Visual Studio 以调试测试适配器,而无需使用诸如在我的适配器代码中添加 Debugger.Launch() 之类的技巧?

【问题讨论】:

    标签: visual-studio csproj vstest vstest.console.exe vstesthost


    【解决方案1】:

    Microsoft 子进程调试工具

    安装由 Microsoft 员工创建的 Microsoft Child Process Debugging Power Tool。这允许您将 Visual Studio 调试器配置为附加到子进程(这是 vstest.console.exe 执行测试的方式)

    安装后,打开您的解决方案并启用子进程调试: 1) 转到以下 Visual Studio 菜单位置的子进程调试设置:Debug -> Other Debug Targets -> Child Process Debugging Settings... 2)启用子进程调试:trueSave 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 进行调试。这里的重点是确保你启用了本地/非托管调试,否则子进程调试工具将无法工作。


    新的 csproj 系统

    编辑或创建一个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>
    

    旧的 csproj 系统

    在项目的调试属性页面中,设置以下设置:

    启动外部程序:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多