Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 944
user310291 Avatar asked Mar 05 '11 00:03

user310291


People also ask

Can you debug a unit test code?

Debug and analyze unit tests with Test ExplorerYou can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.

How do I debug a test in Vscode?

Once you have your launch configuration set, start your debug session with F5. Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug.


1 Answers

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.

like image 63
p.campbell Avatar answered Sep 21 '22 10:09

p.campbell