Saturday, October 27, 2012

Unit Testing in VS 2012

Unit testing is a good software engineering practice which allow developers to assure the quality of the software they development from the beginning. Visual Studio 2012 provides some interesting new features to supports Test driven development mainly for the developers who practice agile practices in their day to day development tasks. In this post I’ll summarize the new features available in VS 2012 in Unit testing & will discuss each feature in detail in the next posts.
  • Test Explorer

    Test Explorer is a powerful tool coming with VS2012 to run the unit tests & view the test results in Visual Studio in a more flexible manner. Test Explorer can be used to mange your test runs of the unit tests which you have written using Microsoft unit testing frameworks for managed and native code and also with the unit tests written using third party & open source unit test frameworks. Visual Studio Extension Manager and the Visual Studio gallery can be used to get these frameworks added. Test Explorer interface provides some useful features to see the test results.
      1. Can filter the test results as we want. ex:- see only the tests which passed
2. Filter tests with matching text using search box facility
3. Can set up to run all the tests after each build for you to verify the quality of the build.
4. You can get the details of the test result of each & every test is being run.
  • Microsoft unit test framework for managed code

    VS 2012 has project Type named Unit Test project which can be used to write unit tests for manages code written in .net framework. Using MS Unit test project type you can write unit test  to analyze & improve the quality of your code. Also VS2012 provides new project type names “Coded UI Unit Test”. This is the automated tests that drive your application through its user interface. These tests will let you verify that the whole application, including its user interface, is functioning correctly. Coded UI Tests are particularly useful where there is validation or other logic in the user interface.
  • Microsoft unit test framework for C++

    One of the main limitations in previous visual studio unit test frameworks is the lack of support for C++ unit testing. VS2012 has overcome this limitation & has improved the level of support for unit test for c++ developers. You can get more details on unit tests on C++ from the following URL:
  • Code coverage tools

    After we write & run the unit tests Code coverage tools in Visual Studio 2012 helps you to determine the proportion of the code being tested in assembly , class & method level. To ensure the quality of the code being released the proportion of the code coverage should be high. Code Coverage Analysis can be used for both manages & unmanaged code. Using code coverage tool you can see the proportion of the code being tested using the source editor. Also this gives you the facility to include and exclude parts of the code from the code coverage analysis as you prefer.
  • Microsoft Fakes isolation framework.

    If you want to isolate the code which you want to create tests from the the code which you don’t Microsoft fake is the solution. By isolation the code being tested make your life easier when identifying where the error is causing when a unit test fails.
    Types of “Fakes
       Stub :-
Replaces another class with a small substitute that implements the same interface. To use stubs, you have to design your     application so that each component depends only on interfaces, and not on other components. (By "component" we mean a class or group of classes that are designed and updated together and typically contained in an assembly.)
       Shim :-
Modifies the compiled code of your application at run time so that instead of making a specified method call, it runs the shim code that your test provides. Shims can be used to replace calls to assemblies that you cannot modify, such .NET assemblies.
We’ll discuss in details on these topics in the next post.
Happy Coding !!!!

No comments :

Post a Comment