Wednesday, 30 April 2008

Writing Unit test cases : Visual studio 2008

One of the great improvements of Visual Studio 2008 brought to developers is the built in support for unit testing. With Unit Testing support, it is very easy for developer to create, execute and repeat unit test cases.

Setting up a test project in Visual Studio 2008 is extremely easy. All it requires is adding a test project into a solution by selecting Test Project template under Test project type.



A test class is generated once the Test project is created. Visual studio automatically mark the test class and method with TestClassAttribute and TestMethodAttribute.



Adding a unit test
It is recommended to create one test class per class to be tested. A test class can be added by either selecting from Add New Test popup or by selecting Unit Test from Add menu.



Alternatively, Unit test can be added by right clicking the method name and select 'Create Unit Tests' in context menu. This brings up the Create Unit Tests screen where (read the entire post)...

kick it on DotNetKicks.com

5 comments:

  1. You state that: "One of the great improvements of Visual Studio 2008 brought to developers is the built in support for unit testing".

    The problem with that statement is that the Microsoft Unit Test Framework was included in Visual Studio 2005! There were some improvements in VS 2008, but all in all, the "new feature" that you decided to tell the world about was over three years old at the time you wrote this post. Code coverage was also included in Visual Studio 2005 but ironcially you didn't mention this feature which imho is the REAL value-add provided by the MUTF.

    I hope you write software better than you fact check!

    ReplyDelete
  2. Thanks Sanjeev,

    I didnt know it was as easy as right clicking a method to create a unit test.

    ReplyDelete
  3. This post really helps. Good job in sharing your thoughts. Keep up your good attitude.

    ReplyDelete
  4. It is amazing how many pedantic, conceited and arrogant programmers you can find out there...
    Thanks Sanjeev! Keep the good work!

    ReplyDelete
  5. Hello Sir,
    I want to ask you that how could i develop test case in vs 2005 in window application.

    Regards
    Mohit jain

    ReplyDelete