简体   繁体   中英

Can I debug while running a VS Unit Test?

I want to unit test a user component which use custom events. when doing this without using VS Unit test Framework debug.assert succeed, when doing the same thing with VS Unit Test Framework, assert fails this is illogical so I want to debug while doing Unit test with VS framework. But It seems I can't because code never pause at debug point that I set.

So is there a way to force it to pause at debug point in that case ?

Update: I mean not in the Test Project itself but in the Targeted Project while running the Test Project.

Yes , with the Visual Studio Test project, you can set breakpoints and step through your code.

Be sure to run your tests with the Debug menu -- Tests -> Debug -> Tests in Current Context. For any given test class or test method, use the keyboard shortcut Ctrl-R Ctrl-T .

When your cursor is in a method ( either a test method, or the code covered by the test ), it'll break on any breakpoints in that method, or any breakpoints anywhere in the code execution path. If your cursor is on the class, or in between test methods, it'll run all tests in the class. Breakpoints will be hit here as above.

The answer by P. Campbell is not exactly right. If you start debugging a project (such as a WCF services site), it is impossible to start any unit tests, debug mode or not. The options to do so are simply grayed out in Visual Studio 2012.

This means you simply cannot debug out-of-process code from a unit test. You can only debug code that was directly called in process by the unit test.

This is a major problem in VS2012 that they need to fix now.

In VS2015, select:

Test->Debug->All Tests

Or you can highlight a specific test in the editor and select

Test->Debug->Selected Tests

在Test Explorer下 - >右键单击要调试的特定测试用例 - >从Context Menu中单击Debug选择的测试用例选项。

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