Debugging Child Processes in Visual Studio

I am currently on a mission to create acceptance tests for all new development I embark upon. Well, where it makes sense to do so.

Up until very recently when I encountered a problem and I needed to debug the target application I would take one of two approaches.

  1. Create an acceptance test to get me far enough, in terms of setting up test data/environment, to be able to debug the app and see what was going on.
  2. Put a breakpoint on the step within the acceptance test that executed my target application and stop the debugger.

Neither of these are ideal, or indeed, a very nice work flow experience.

So, I decided to hunt down a way to debug both my acceptance test code and my target application. The ideal situation would be for me to click the little bug icon in my resharper test runner.

Debug Unit Tests Button

After practising a bit of google-fu, I stumbled across this little gem.

https://blogs.msdn.microsoft.com/visualstudioalm/2014/11/24/introducing-the-child-process-debugging-power-tool/

Basically, it adds the ability for child processes spawned during a debugging session to be automatically included in your current session. There are other tricks around forcing apps to be automatically debugged, by hacking the registry, but that involves some awful workflow things. Namely …

  • Having to chose which debugger instance to use, or create a new one
  • Hacking the registry!

Also, it doesn’t attach to the process quite soon enough if your target application, spins up quickly and gets on with it’s job too fast for the attachment process.

This tool¬†copes with that situation and it “just works”. Providing you set up a few things in your acceptance test project.

Firstly, you need to install the tool and go into the “Child Process Debugging Settings…”

Child Process Debugging Settings Menu

Then you need to “Enable child process debugging” …

Enable child process debugging

Next, go to the properties of your acceptance test project, and enable native code debugging …

Enable native code debugging

and, you’re all set.

You can now set breakpoints inside your target application, debug your acceptance test in your favourite test runner, and you will be able to step through the code in your target application using whatever test data/environment you set up in your acceptance test.

I hope you’ll agree this is a much nicer workflow.

Advertisements

2 responses to “Debugging Child Processes in Visual Studio

  1. Pingback: Running a console app programmatically (within a test) | antony_scott

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s