Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

September 16, 2012

101 Ways to Run Tests with Visual Studio 2012

Filed under: C#,Testing,VB.NET,Visual Studio @ 3:59 pm

OK 101 is an exaggeration, but there are many ways to run your tests in Visual Studio 2012.

From the test code file

While you are writing or editing a test method, you can right click anywhere within the method and run or debug the test.

image

[Red rectangle added for illustration.]

All of the tests in Test Explorer are displayed "grayed out" except for the executed test as shown below. Click on the test to view the result details in the right pane (or bottom pane if your Test Explorer is sized to display vertically).

image

From the code editor, you can also run all of the tests within a code file by right-clicking anywhere within the code file, but outside of a specific method. Clicking in an empty space between two methods, for example, will execute all of the tests in the code file.

From Test Explorer Toolbar

View the Test Explorer window using Test | Windows | Test Explorer. The Test Explorer window toolbar provides many ways to run your tests.

image

  • Run All
    Runs all of the tests displayed in Test Explorer. If the list of tests are filtered by search criteria, only the filtered tests are executed. (See this prior blog post for information on searching within Test Explorer.)
  • Run Failed Tests
    Runs only the failed tests displayed in Test Explorer.
  • Run Not Run Tests
    Only runs the tests displayed in Test Explorer which were not previously run since opening Visual Studio.
  • Run Passed Tests
    Runs only the passed tests displayed in Test Explorer.
  • Repeat Last Run
    Runs the prior test run again, but only on the files displayed in Test Explorer. If you Run All then filter the tests in Test Explorer then Repeat Last Run, only the filtered tests will be executed again.

From Test Explorer Context Menu

Right-clicking on a test in Test Explorer provides run options.

image

You can select a single test, multiple tests using the Ctrl and Shift keys, or all tests using the Select All option from the context menu. Then you can Run or Debug the selected tests.

Use these techniques to run only the tests you are interested in.

Enjoy!

6 Comments

  1.   Konstantin Tarkus — September 25, 2012 @ 8:41 pm    Reply

    Is there a way to make Visual Studio run tests in a background while you’re writing code, executing them on a dedicated machine?

  2.   DeborahK — September 26, 2012 @ 6:05 pm    Reply

    Hi Konstantin –

    Yes, you can execute your unit tests on a dedicated machine following the information provided here:

    http://msdn.microsoft.com/en-us/library/ms182465.aspx

    Hope this helps.

  3.   DeborahK — October 4, 2012 @ 1:40 am    Reply

    Hi Konstantin –

    I also recently wrote a post on running the tests in the background after each build:

    http://msmvps.com/blogs/deborahk/archive/2012/09/26/running-your-unit-tests-continuously.aspx

    Hope this helps.

  4.   Howard — October 10, 2012 @ 11:00 am    Reply

    WHAT?

    If 101 was binary, it would still be three more ways than the actual number of ways to organise and run tests in VS2012.

    Test management in VS2012 is much worse than with VS2010.

    It’s the main reason I have not uninstalled VS2010 as the Testing functionality there is so much better.

    I code in VS2012, but test in VS2010

  5.   DeborahK — October 10, 2012 @ 4:24 pm    Reply

    Hi Howard –

    LOL on the binary! I agree that we lost lots of test functionality between VS 2010 and VS 2012. I often have both up while I am coding also, using VS 2010 to work with my database projects, compare database data, and generate my unit tests from the functions.

    I hope with the quarterly Visual Studio updates that we will get more test features soon.

    Thanks for your comment.

  6.   Patrick Davey — April 10, 2013 @ 4:11 am    Reply

    Why does winform opendialog no longer work in vs2012 unit tests?

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2019 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs