This project is read-only.

How to debug tests

Jul 16, 2010 at 9:40 AM

Hi, maybe I'm missing something obvious, but how do you debug your tests from within VS when the application you are testing needs to have focus while you need to have focus in VS to debug the test code?

Jul 16, 2010 at 7:06 PM


I debug mine using two monitors, one for VS and another where the application under test is launched. I set breakpoints as usual and when they are fired the focus changes to VS and the application under test "freezes".


Jul 16, 2010 at 8:50 PM

But when you hit F10 to go to the next line, doesn't the just executed line of code - imagine it was a line to type something into a control on the tested form - try to type the text into the focused VS text editor instead? That's what I'm experiencing at least.

Jul 16, 2010 at 9:21 PM
I think there are some things you can't debug in each detail.

Such things are pressed STRG/Shift to multiselect or context menus

here you can only debug one step before and the next step after

so you can only debug that F10 has the effect you want or not (the stepp after F10).

Jul 19, 2010 at 12:25 PM
Edited Jul 19, 2010 at 12:28 PM


It will not work if you send keys. For example, I am able to debug this case:

var expression = wiz.Get<TextBox>(SearchCriteria.ByAutomationId("Expression"));
expression.Text = "1+2";

But not this other equivalent:

var expression = wiz.Get<TextBox>(SearchCriteria.ByAutomationId("Expression"));

When I hit F10 on the last line White sends the keys to Visual Studio which now has the focus. This is, I think, unavoidable since only one control can have focus.

Other cases like this:

var check = _wizard.Get<RadioButton>(SearchCriteria.ByAutomationId("SomeCheckBox"));

Debugs just fine.

I hope this helps,

P.S. By the way, debug doesn't always work. I have found several cases in the past where the test crashes with odd exceptions in the middle of the test only when I am debugging it.

Jul 19, 2010 at 6:25 PM

Thanks Jose, that confirms what I suspected. The problem is that often I need to send keystrokes directly instead of setting a control's property value, for example to send certain special keys. I was wondering if there would be a way to keep the window of the app under test always on top, like you can do, for example, for the Windows Task pane. That might at least mitigate the issue partially.

Jul 19, 2010 at 7:57 PM

I am not sure if this solves the problem but you can set the Window property Topmost="True" to force your application in front of all the others. I did not try this but I would be interested in knowing your results if you do.