Attaching to a Process using VS.NET Automation Model

I've recently changed NUnitAddin so that it runs unit tests in an external process. It controls and communicates with this process using .NET remoting. Because tests are run in an external process it's possible to attach the VS.NET debugger set breakpoints on them. When I manually attach the CLR debugger (as follows) it works great.

Debugging Tests

I've added a 'Debug Tests' item to the Tools menu with the intention of automatically attaching the debugger to the correct process. It is strait forward enough to query the remote test runner for its process id. After doing this I’ve tried attaching the VS.NET debugger using the following code…

public void AttachToProcess(int processId)

{

foreach(EnvDTE.Process process in DTE.Debugger.LocalProcesses)

{

if(process.ProcessID == processId)

{

process.Attach();

DTE.Debugger.CurrentProcess = process;

}

}

}

The debugger appears to attach to the process, but when I try running a test it just stops. I get the same effect if I manually select CLR and Native debugging at the same time. I suspect this is what’s happening when calling the above code.

At this point I'm pretty stumped. I've done a workaround that involves launching the test runner process using a project with debug type 'Program'. This kind of works, but is far from ideal.

What I really need is a way of programmatically attaching a specific instance of VS.NET to a process using CLR debugging. Any help would be greatly appreciated. Can anyone shed light on why selecting CLR and Native debugging at the same would cause an application to freeze?

I've made a zip of the addin that uses the above code here. Do a search for 'AttachToProcess' in the 'NUnitAddin\Connect\NUnitAddinConnect.cs' file. The main solution target will compile, install and launch a test solution using the addin (it couldn't be easier). Once you've done that you're ready to 'Debug Tests' on the 'Tools' menu and 'Run Test(s)'...

Published Sunday, February 9, 2003 4:34 PM by Jamie Cansdale
Filed under: ,

Comments

# I don't get it

I'm sorry. I don't get what exactly I'm supposed to do now to debug a test. Things seemed to work fine before--have we really taken a step forward here?
Also, the new version of the addin no longer shows the tests that were not run (due to the Ignore attribute).

Monday, February 10, 2003 2:31 AM by djackman

# It doesn't work at all

Well, I tried adding a new test fixture with the addin (which worked okay but was pretty klunky). I swear that's all I did. Now I can't run tests at all. I just get exceptions within the addin.
I have work to do, and I don't have time to battle with this. I'm going to revert back to the previous version of the addin. Let me know when a working version is ready.

Monday, February 10, 2003 2:49 AM by djackman

# It doesn't work at all

Well, I tried adding a new test fixture with the addin (which worked okay but was pretty klunky). I swear that's all I did. Now I can't run tests at all. I just get exceptions within the addin.
I have work to do, and I don't have time to battle with this. I'm going to revert back to the previous version of the addin. Let me know when a working version is ready.

Monday, February 10, 2003 3:14 AM by djackman

# break

Didn't you forget a <b>break</b> in your loop?

Thursday, February 13, 2003 8:05 AM by Fabrice

# Fixed

I've fixed the 'ignore attribute' issue. I think the current version is new pretty stable. I haven't touched the TestFixture wizard though. There also 'New Project...' wizards for every project type (including JUnit!). I've never had any problems with them.

Thursday, February 13, 2003 3:06 PM by Jamie Cansdale