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:
- Create a web project.
- Add a new class
- write a method, say
public String hello() { return “world”; } - Go to Test menu,
- Click New test.
- It will ask to create a test project first, give
- Then select add new test
- select unit test wizard
- select the files you want to test.
- 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 valueDim 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..
Comments
Leave a Reply