visual-studio 在 Visual Studio 2008 中调试时只执行一个单元测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/266716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:52:20  来源:igfitidea点击:

Execute only one unit test while debugging in Visual Studio 2008

visual-studiovisual-studio-2008unit-testing

提问by Michael Kniskern

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.

有没有办法在调试时选择要在 Visual Studio 2008 单元测试项目中执行的测试方法?我想调试一个特定的测试,而无需在每个调试会话期间执行我的其他测试方法。

回答by Jon Skeet

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

单击测试方法名称,然后按 Ctrl+R、Ctrl+T。(或转到当前上下文中的测试/调试/测试。)

回答by Dennis van der Stelt

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+ T= 在上下文中运行测试。这很容易在测试中触发。
CTRL- R+ A= 运行所有测试
CTRL- R+ C= 运行类中的所有测试
CTRL- R+ N= 运行命名空间中的所有测试
CTRL- R+ F= 运行所有已检查的测试(适合重新运行所有失败的测试)

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

CTRL- R+ CTRL- T= 在上下文中调试测试,即。它还附加了调试器
这也适用于所有其他组合。

回答by Rob Prouse

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.

可能还有其他方法,但我安装了TestDriven.NET。它允许您右键单击测试方法(MSTest、NUnit、MbUnit 等)并选择在调试器中运行。我强烈推荐它。

回答by Rob Prouse

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.

或者,您可以创建一个测试列表(Test->Create New Test List),并使用它来选择要运行的测试。您还可以使用 is 来禁用和删除测试。

回答by Jason Snelders

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.

如果您想在 ASP.NET 解决方案下运行测试时进行调试,请查看 MSDN 文章“如何:在 ASP.NET 解决方案中运行测试时进行调试”,网址http://msdn.microsoft.com/en-我们/图书馆/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.

我今晚必须这样做,并部分遵循了“在 ASP.NET 开发服务器上运行时调试”的说明,在 web.config 和方法开始时的 System.Diagnostics.Debugger.Break() 语句中设置。但是,我使用“Debug Checked Tests”命令(Ctrl+R、Ctrl+T)执行,该命令产生了即时调试器提示并运行了一个新的 Visual Studio 实例(我使用的是 VS2010 Beta2)。它运作良好。

回答by peSHIr

Like Willmentioned, 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.

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