Category: Unit Testing

Unit Testing Improvements in Visual Studio 2011

In the past, one big reason why people did not embrace MS Test (I think) is because Visual Studio 2008/2010 did not provide a good environment that supported Unit Testing. Sure it did had MS Test and its runner, but it was weak compared to Test Runner from Jet Brains ReShareper or TestDriven.net. I think someone at Microsoft listened to and as I result, there is many notable improvements in this area in Visual Studio 2011.

Below screenshot shows Visual Studio 2011 with Unit Testing related Menu marked.
Under Run Unit Tests, options are all self explanatory.

Menus shown below:

There is an option Unit Test > Unit Test Setting called “Run Tests after Build”, using by which you can always run all the unit tests after each time you build. This is a good practice, and if you manage it well i could be useful. Personally I think I would always kick off my test/s manually, its just my preference now. Also I would have a well scripted local build that can take care of building all components and running my unit and integration tests automatically.

BYO TF (Bring your own Test Framework)

I am not a fan of Ms Test (I think I made that clear earlier), I use NUnit and I have no idea to switch to another framework. What I like about this edition of Visual Studio, is that, it supports other testing frameworks like NUnit through test adapters. If you are using NUnit like me, download NUnit Test Adapter from here > Link
Visit this page for information on all available at this time > Link

Another way of getting third party frameworks is to use the Extension Manager, Click on Tools > Extension Manager to launch extension manager, then under Online Extensions, Expand Visual Studio Gallary, Select Tools, and click on Testing.

Test Explorer

Test Explorer lists all the Tests grouped by Failed, Passed, etc. You can right click and run individual tests, or debug tests.

Code Coverage

Visual Studio 2011 packs a code coverage tool also. This is a great feature addition. In the past, I had to purchase a tool like dotCover to do this for me. By double clicking on each line in the coverage results window, you can inspect the parts of your code that lacks coverage (or be proud to see every piece of code has 100% coverage and green)

More later, Happy Coding
Cheers!

Are you xUnit or MSTest?

Which unit testing framework do you use? There are many to pick from, most of the better ones are xUnit based and Visual Studio comes with its on testing framework. Personally I would stick with NUnit, because it works well and integrates well with ReSharper. Resharper/TestDriven.Net can run most of the unit testing frameworks including Microsoft’s. I was thinking about unit testing frameworks this morning (we wanted to pick one for our project, we as a group chose MbUnit!) and found that there are around 20 different unit testing frameworks listed in Wiki for .Net programming languages!!! Here is the link (I will save one google search 🙂

And did I say ReSharper is the best productivity add-on that has ever happened to Visual Studio ??

[Update] While we are on topic of testing frameworks, in the wiki link I was not able to find a link to SOAPUi, web service testing tool. Check out their site, they even have an interesting article on ways to hack (or prevent it) a web service login !