Visual Studio 2013 custom Test Adapter: how to debug?
Asked Answered
K

2

8

I am writing a custom Visual Studio Test Adapter, and was wondering: how can I debug it? Right now I am following these steps:

  1. Adding a number of logger.SendMessage() log lines into my adapter code.
  2. Building the adapter
  3. Copying the dll from step 2 above into the Test Extensions folder (Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions)
  4. Run some tests from the console: vstest.console.exe dummy.project.with.tests.dll
  5. View the log output

Is there a way I can debug my test adapter in VS2013 as it's running a test?

Note: my research found a comment in this post that says to use Debugger.Launch() - but I don't know how to activate that to achieve what I want.

Kibitzer answered 10/7, 2014 at 16:9 Comment(0)
E
5

Step 1: Install the Adapter

In the link you provided, a VSIX project is created to install the adapter. In the VSIX project there is an option (in the VSIX tab) to deploy the adapter automatically to the VS Experimental hive on build.

If you are using vstest.console.exe you do no have to do this.

Step 2: Run the tests using the Adapter

Easiest way to do this and attach the debugger immediately is via the Debug tab in your project settings. Set this to start an external program and the debugger will be attached to the program whenever you run it in Debug mode.

If you are running tests through VS:

devenv.exe /rootsuffix Exp

If you are running tests through vstest.console.exe and you did not install the adapter on your main VS:

vstest.console.exe dummy.project.with.tests.dll /TestAdapterPath:"TestAdapterBuildDirectory"

If you are running tests through vstest.console.exe and you did install the adapter on your main VS:

vstest.console.exe dummy.project.with.tests.dll /UseVsixExtentions:true

Step 3: Attach the debugger to all the processes your Adapter will be run from

Use the Debug > Attach to Process option in Visual Studio.

In VS2013 most processes will hang around between test runs, so you can run the test once to start the processes, then attach to them before running the tests again. In VS2015 these processes don't tend to hang around long at all so you have to either attach to them very fast, or add a large sleep to your test executor to give you extra time to attach in.

If you've attached to the right process, and your test adapters were compiled with symbols, you should have no problem adding a breakpoint wherever you need in your adapter code.

The processes you need to attach to are as follows

VS2013

  • devenv.exe - The VS instance. This is where any Test Container Discoverers you have created will be run.
  • vstest.discoveryengine.exe - The discovery process. This is where any Test Discoverers will run, after being sent the test containers.
  • vstest.executionengine.exe - The execution process. This is where any Test Executors will be run, after being sent the test cases. Therefore this is what you need to attach to if you want to see a test running.

VS2015

Some of these processes still exist, but you also need to attach to a number of processes, all called TE.ProcessHost.Managed.exe. If you're not sure of which of these processes to attach to, attach to them all. Some will be for discovery and some will be for execution, though the execution processes will disappear very fast.

vstest.console.exe

This does not use the Test Discoverer or the Test Container Discoverer. If you are attached to the actual console program you should be able to inspect the running tests by adding breakpoints to the Test Executor. If this is not working I suspect the Adapter is not being run at all and you should look more closely at the /TestAdapterPath and /UseVsixExtensions options.

Entwistle answered 21/12, 2015 at 0:44 Comment(0)
M
0

Not a lot of experience in that. Related to step 3., you could also think of installing (and uninstalling) the test adapter VSIX package from command-line, with:

REM install
vsixinstaller /q "C:\Path\To\Your\Adapter\bin\Debug\YourAdapter.vsix"

REM uninstall
vsixinstaller /q /a /u:YourVsixManifestId
Melchor answered 18/8, 2015 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.