Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 custom Test Adapter: how to debug?

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.

like image 647
Vishal Bardoloi Avatar asked Jul 10 '14 16:07

Vishal Bardoloi


People also ask

How do I debug a specific test case in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do I debug a test code in Visual Studio?

To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.

How do you debug a test case?

To debug a failed test case you should: check that the input data is correct (open the test case to view and/or update the base level attribute values) check that the expected results are correct (in the Test Report, click on the expected result to view and/or update the expected results for that attribute)


1 Answers

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.

like image 145
Andyrooger Avatar answered Oct 13 '22 05:10

Andyrooger