Deborah's Developer MindScape

         Tips and Techniques for Web and .NET developers.

October 25, 2009

Unit Testing: Execution

Filed under: C#,Testing,VB.NET @ 5:50 pm

Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests.

[To begin with an overview of unit testing, start here.]

This prior post demonstrates how to build a unit test using the "Create Unit Tests…" feature of the Code Editor. This post demonstrates how to execute a unit test.

NOTE: This post assumes you have already generated or created at least one unit test.

To execute one or more unit tests:

1) Open your solution in Visual Studio.

The solution should include both the project(s) to test and the test project(s).

2) Select Test | Windows | Test View from the menu to view the Test View window. This window contains every method marked with the TestMethod attribute.


The solution used for the screenshot above has two LastNameTest unit tests: One for the VB example and one for the C# example. If you coded along  from the prior unit testing post, you will only have one for whichever language you selected. If you have been creating unit tests for one of your projects, you may have hundreds of tests in this list.

To execute unit tests:

1) Select one or  more tests from the list of tests in the Test View window.

You can add columns and sort the list or use the filter feature to make it easier to locate and select the desired tests to execute.

2) Click the Run Selection button in the upper left  corner of the Test View window or right-click on any selected test and select "Run Selection" from the context menu.

The selected test(s) will then execute, displaying their status in the Test Results window:


When the test is complete, the Test Results window will look something like this:


Both of  the tests shown in the above screenshot are marked as Inconclusive because the generated unit testing code used the Assert class Inconclusive method. The generated unit testing template is designed to prevent a false positive. It generates an inconclusive result until you update the unit test with correct valid and invalid values and remove the Inconclusive method call.

To see more information on the result of the test, double-click on a test result.

To run the test again, use the Run or Debug buttons at the top of the Test Results window.

If any of  the tests don’t pass, they are marked as Failed in the Test Results window as shown below.


Double click on any of  the failed tests to view the test results:


The Error Stack Trace at the bottom of this window gives you further information on the source of the failure. Click on any link in the stack trace to jump to the associated location in the code.

You can also debug the code as the test is executing if you "Debug Selection" option instead of the "Run Selection" option.

After you update the unit tests with valid code and the tests pass, the Test Results will appear as follows:


Notice the color-coded green passing indicator.



  1.   B. Clay Shannon — October 27, 2009 @ 11:51 am    Reply

    Wow! Unless the computer’s date/time was tweaked forward, this article was created just a couple of days ago – usually the dates shown are months if not years in the past.

    Anyway, my question is: Can random values be sent to these tests, such as in the case of testing last names, could it be sent a bunch of different strings, such as:



    I don’t know if I will pass this way again, so if you really want me to see a reply, please email it to

  2.   DeborahK — October 27, 2009 @ 5:44 pm    Reply

    Hi B. Clay –

    I don’t know where you are reading an odd date, but I see 2009-10-25 everywhere (last Sunday). The 15:25:40 is the time (hour, minutes, seconds) Where are you seeing a date in years past?

    Regarding your question, yes. The next article in this series will cover how to test properties in further detail.

    Thanks for coming by the blog.

RSS feed for comments on this post. TrackBack URI

Leave a comment

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