views:

1740

answers:

6

Is there a way to select which TestMethods you want to execute in Visual Studio 2008 Unit Test project while debugging? I want to debug one particular test without having my other TestMethods execute during each debug session.

+3  A: 

There are probably other ways, but I install TestDriven.NET. It allows you to right click on a test method (MSTest, NUnit, MbUnit, etc) and select Run in Debugger. I highly recommend it.

Rob Prouse
TestDriven.NET looks like a great Visual Studio add-in, but I have to purchase it...:(
Michael Kniskern
+11  A: 

Click on a test method name, then press Ctrl+R, Ctrl+T. (Or go to Test / Debug / Tests in Current Context.)

Jon Skeet
That worked. Thanks for the tip.
Michael Kniskern
Good tip for the day.
bovium
Also learn about the other testing keyboard shortcuts: Ctrl+R, (Ctrl+)C and Ctrl+R, (Ctrl+)A where C and A stand for Class and All respectively. The control in the second key of the chord determines whether you'll run or debug the test(s).
peSHIr
+2  A: 

You've got two options when running tests. Look at your Test Tools toolbar. There are four buttons: Run tests in current context, debug tests in current context, run all tests, and debug all tests in solution.

When you want to debug a single test, you can put your cursor in the body of the test and click one of the "current context" test run buttons. To run all tests in a class, put the cursor at the test class name and click one of those buttons.

Alternatively, you can create a test list (Test->Create New Test List), and use that to select the tests you want to run. You can also use theis to disable and remove tests.

Will
Same result, different implementation as Jon's suggestion...+1
Michael Kniskern
A: 

If you want to debug while running your tests under an ASP.NET solution, check out the MSDN article "How to: Debug while Running a Test in an ASP.NET Solution" at http://msdn.microsoft.com/en-us/library/ms243172.aspx.

I had to do this tonight and partially followed the instructions for "Debugging While Running on ASP.NET Development Server", setting in web.config and the System.Diagnostics.Debugger.Break() statement at the start of the method. However, I executed with the "Debug Checked Tests" command (Ctrl+R, Ctrl+T) which produced a Just-in-time debugger prompts and ran up a new instance of Visual Studio (I'm using VS2010 Beta2). It worked well.

Jason Snelders
A: 

Like Will mentioned, you can use test lists for all kinds of "test herding" scenarios, as each unit test in a solution can be a member of zero-or-more test lists and you can create a tree of test lists in Test -> Windows -> Test List Editor.

peSHIr
A: 

CTRL-R + T = Run test in context. This can easily be triggered inside a test.
CTRL-R + A = Run all tests
CTRL-R + C = Run all tests in class
CTRL-R + N = Run all tests in namespace
CTRL-R + F = Run all checked tests (good for rerunning al failing tests)

CTRL-R + CTRL-T = Debug test in context, ie. it also attaches debugger
This also works for all other combinations.

Dennis van der Stelt