Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run/Debug Test in Current Context with Visual Studio 2012

In VS2010, one can Run or Debug Tests in Current Context.

That made it easy to click on a test I had just added or modified and run it (Ctrl-R T) or debug it (Ctrl-R Ctrl-T). (or with my gaming keyboard... G1 ;-)

The only way I can find to run a specific test is to locate it in Test Explorer and run it from there. That requires shifting my focus away from the code I'm working on.

Is there something equivalent to Current Context in Visual Studio 2012?

like image 520
Eric J. Avatar asked Aug 16 '12 19:08

Eric J.


People also ask

How do I run a test in debug mode in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do I use test Explorer code in Visual Studio?

Testing Explorer# The Testing Explorer is a tree view to show all the test cases in your workspace. You can select the beaker button on the left-side Activity bar of Visual Studio Code to open it. You can also run/debug your test cases and view their test results from there.

How do I debug a code in Visual Studio?

When you are editing code (rather than paused in the debugger), right-click a line of code in your app and choose Run to Cursor (or press Ctrl to F10). This command starts debugging and sets a temporary breakpoint on the current line of code.


2 Answers

It turns out that one can right-click on the source code of any of:

  • A specific test (public void MyTest())
  • A class containing tests (public class MyTestClass)
  • A namespace containing tests (namespace My.Project.Test)

and get a context menu to either run or debug tests within each given scope. (Note: Text in Context Menu does not change)

This has proven the most useful method of selectively running tests for me.

like image 173
Eric J. Avatar answered Oct 08 '22 03:10

Eric J.


I was just looking for this myself and happen to come across this tidbit.

If you right click inside the test you want to debug in the current context and select run tests or debug tests it will only run that one.

If may appear that all the other tests in that file fail according to the test explorer, but it should work.

https://connect.microsoft.com/VisualStudio/feedback/details/745762/cant-run-or-debug-tests-in-current-context

like image 41
John Avatar answered Oct 08 '22 02:10

John