Execute only one unit test while debugging in Visu

2020-02-24 11:40发布

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.

6条回答
啃猪蹄的小仙女
2楼-- · 2020-02-24 12:09

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.

查看更多
趁早两清
3楼-- · 2020-02-24 12:14

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

查看更多
倾城 Initia
4楼-- · 2020-02-24 12:15

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.

查看更多
够拽才男人
5楼-- · 2020-02-24 12:20

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.

查看更多
虎瘦雄心在
6楼-- · 2020-02-24 12:21

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.

查看更多
The star\"
7楼-- · 2020-02-24 12:25

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.

查看更多
登录 后发表回答