New Unit Tests features of Visual Studio 2012
Visual Studio 2012 was already launched some time ago. A lot of new features were introduced in this new version. Some of the changes made to Visual Studio 2012 are big and in some aspects, the difference between the old version of Visual Studio and the new one are like the differences between Windows 8 and Windows 7.
I think that a lot of developers have already played a little with this new version of Visual Studio. The first thing that you notice after installing is the time necessary to load the new Visual Studio – it loads very quickly. The second thing is the new UI, that is Metro like.
One area where Visual Studio 2012 made a big step forward was Unit Testing. A lot of new features were introduced that not only increase the developer’s productivity, but also increase the quality of the code. In the next part of the post we will discover what new features were introduced from the unit testing perspective.
Run tests after each build
In the old version of Visual Studio, we didn’t have a mechanism for running unit tests after each build. That is why we had to click on “Run All Tests” each time when we built the solution. This could become annoying after a while. Visual Studio 2012 already has the build feature and it can be deactivated with only one click.
All the tests run in the background, without bothering us.
Debug/Run Tests Directly from Code
How many times did you have to go to the Test Explorer window in order to run your current test. From now on, Visual Studio 2012 has a shortcut in the menu that will run the tests selected in the code.
Group and Run Unit Tests Based on Category
From now on we can add one or more categories to our unit test. This attribute can be added not only to each test in part but also to the unit test class. Using this feature allows us to run unit tests only from a specific category. This is a great feature not only on the developers’ machine, but also on the build machines.
We need to specify the TestCaseFilter option in order to be able to run the unit tests that have a specific category from the command line:
Vstest.console.exe myFooProject.dll /TestCaseFilter:”TestCategory=”Atomic”
Until now, if we had a unit test that would check if a method throws an expected exception; we would have to decorate our method with an attribute. But this is not the best solution, because there were cases when we could not determine the source of the exception precisely.
This feature is only available for Windows Store Application right now. We hope that this new feature will also become available for other types of projects.
Smart unit test discovery
The algorithm that is used to discover new unit tests was improved New unit tests are usually discovered extremely quickly. Gone are the days when we had to rebuild the solution and wait until the new unit tests were discovered by Visual Studio.
Unit testing is a lot easier with this new version of Visual Studio. These are only a few of the new features that Visual Studio 2012 brings to the table. You can try it and discover these new great features for yourself.