Shaikh Sonny Aman’s Blog

previously www.mailtoaman.com

How to unit testing with Visual Studio Team System 2008

Posted on | April 13, 2008 |

 

Testing is a vital part of any software project. In modern development
processes it is an umbrella task.

Visual Studio Team System 2008 offers an excellent way to perform
various types of test. It made testing as easy as it gets.

Lets see how to perform unit testing over a class.

Steps:

  1. Create a web project.
  2. Add a new class
  3. write a method, say
    public String hello() { return “world”; }
  4. Go to Test menu,
  5. Click New test.
  6. It will ask to create a test project first, give
  7. Then select add new test
  8. select unit test wizard
  9. select the files you want to test.
  10. Click Ok.

You will find  XXXTest.vb file is created for every class.
XXX is the class name.

There a test class is created which has public routines like
YYYTest() for all the methods in XXX class. Here is a sample
descripion of such a basic function:

Public Sub helloTest()
        Dim target As Class1_Accessor = New Class1_Accessor ‘ TODO: Initialize to an appropriate value

        Dim expected As String = “Worldss” ‘ TODO: Initialize to an appropriate value
        Dim actual As String
        actual = target.hello
        Assert.AreEqual(expected, actual)
        Assert.Inconclusive(”Verify the correctness of this test method.”)
    End Sub

Look at the bolded word “Worldss” which I entered as the expected
result, certainly it is not expected, but is given to get a test failed :)

Now, run Test->Run->All tests in solution Ctr+R,A to run the test.
You can also run the test related to only the current context.

Enjoy programming… enjoy real programing.. :D

Comments

Leave a Reply