Oct 262012
Share...Tweet about this on TwitterShare on FacebookShare on Google+Share on StumbleUponShare on LinkedInPin on PinterestShare on TumblrShare on RedditDigg this

Microsoft Visual Studio 2012 comes with a large amount of new features and improvements in almost all areas. The changes introduced in the “unit testing” and generally “testing” area are very significative.
I’ve read the following sentence in one of the Microsoft slides and I couldn’t agree more:

The Visual Studio 11 Unit Testing experience is focused on developers writing and running unit tests while they write their code.


Microsoft was working on making the testing framework extensible, indeed it allow us to use other testing frameworks such as xUnit.net and Nunit, something that in the past, in order to have something built into Visual Studio we had to use external plugins such as Resharper or others. All this can be seen in the below picture that depicts the current Microsoft Visual Studio Unit Test Platform that is in fact a Unit Test Runners-Runner. Yes, the responsibility of this layer is to run the third party unit test runners and it is supposed to be the “glue” between the user and the actual underlying unit testing framework.

VS2012 Unit Testing Architecture

Test Explorer

Visually, the most important addition to the Visual Studio Unit testing is the so called Test Explorer

Test explorer supports a number of features (as illustrated in the picture) such as:
Test Explorer

  • Search: it is possible to search within the test names and execute only those displayed in the search
  • Red-Green bar: Bar at the top of the window will display if the tests have been failed (red) or if everything have run smoothly.
  • Most important tests will be shown first (at the top)
  • Timings: Each tests has the duration so we can see quickly how long it takes for a test to execute and fix it if it runs slowly.
  • Shows tests from any framework.
  • Run details: there are details being shown in the bottom part that will tell why the test failed or other information.

Code Coverage

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested.

In the picture below you may see how the information are displayed directly in Visual Studio showing which part of the code haven’t been covered tested (in red) with a number of statistics around it.

Previously in order to see such number of statistics we had to use third party tools such as NCover, JetBrains dotCover or others.

VS2012 Unit Test Code Coverage

Isolating code for better testing

There is another improvement named VS11 Fakes framework that lets us isolate almost anything in .NET. There are two flavors of fakes:

  • Stubs: concrete implementations of interfaces or abstract classes. VS offers an easy way of creating stubs something that we previously had to do manually or using third part frameworks such as Moq, or others. It is not fully a replacement but a good start.
  • Shims: run-time interception lets you replace calls, even those from the .NET Base Class Library.

Check this and this videos if you like to see how to use the new Visual Studio 2012 fakes framework.

Fakes and shims visually represented:

(c) Microsoft.com

Continous Testing

Continous testing in Visual Studio 2012 gives a possibility of continuously running the tests withing the solution. It helps you with the way you do TDD by taking care of all compiling and testing in the background to help you work more efficiently.

This framework could potentially replace the third party tools such as ContinousTest, NCrunch, or others.


Visual Studio 2012 has a list of improvements that will make the unit testing simpler and effective. The number of features is quite large so I encourage you further check and experience it by yourself. As I haven’t had the time to fully try all the above explained items, I am not yet sure if the above listed features would replace the other third party frameworks, but this is already a good step forward. Microsoft is showing us that it is moving into the right direction.

    Share...Tweet about this on TwitterShare on FacebookShare on Google+Share on StumbleUponShare on LinkedInPin on PinterestShare on TumblrShare on RedditDigg this

    I'm a Software Developer and Solution Architect interested in Software Development, Object-Oriented Design and Software Architecture all this especially bound to the Microsoft.NET platform.Feel free to contact me or know more in the about section

    Leave a Reply

    dauphinais_rpo@mailxu.com scotland204@mailxu.com