Micah
Micah

Reputation: 116180

How to run a test while attached to a process in Visual Studio

I'm trying to debug some web services. I have a number of integration tests setup. I want to attach the debugger to my web process and then execute one of my tests. The problem is Visual Studio doesn't seem to allow me to run a test while I'm already attached to a process. Is there any way around this? The only way I've been able to do it is set a breakpoint in the test prior to calling the webservice, debug the unit test, and then once it hits the breakpoint attach the debugger to my webservice process. That's too many steps.

Upvotes: 4

Views: 2189

Answers (2)

Reasurria
Reasurria

Reputation: 1858

I know this is late but it's still relevant, at least up to VS2019.

What I do to work around this is this:

  1. Attach the debugger to my web service
  2. Detach the debugger
  3. Take note of the 'Reattach to process' shortcut. I think the default is Shift+Alt+P
  4. Run the unit test
  5. Immediately hit the reattach shortcut

Unless your test starts up exceptionally quickly, this method will reattach the debugger before the tests start running.

Allen's answer is better if your machine can handle 2 instances of VS.

Upvotes: 1

allen
allen

Reputation: 4647

No I don't believe you could. You can however start up a second instance of visual studio and attach it to your web process with the appropriate breakpoints.

Upvotes: 4

Related Questions