简体   繁体   中英

Execute only one unit test while debugging in Visual Studio 2008

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.

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

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.

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.

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.

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.

Will提到的一样,您可以将测试列表用于各种“测试放牧”场景,因为解决方案中的每个单元测试都可以是零或多个测试列表的成员,您可以在Test创建测试列表树 - > Windows - > Test List Editor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM