Visual Studio Test framework to create tests for your code

While writing software over a period of weeks or months, various components of the software get completed at various times. You’ve tested and you’re satisfied they work, and you move on to develop another feature. Or you might check in the source code and somebody else on your team might break your code accidentally with […]

While writing software over a period of weeks or months, various components of the software get completed at various times. You’ve tested and you’re satisfied they work, and you move on to develop another feature. Or you might check in the source code and somebody else on your team might break your code accidentally with another checkin. This break might not be discovered for days or months.

Checking in test code for the feature alongside the feature code can help prevent such scenarios. These “unit” tests must be simple to run, easy to develop and maintain, and enable you to test your code well. Running the tests might take a minute, but give you the peace of mind that the change you made didn’t break other features. (Or if they did, they might be intentional feature changes, so the tests can be updated)

Software originates at the developer and passes through various stages, like through testing, building, customer installation, Discovering the bug closer to the developer and the time of development is very valuable: waiting til after the tester or customer gets the application is way too late!

Start VS 2008 (I believe it has to be Visual Studio Team Server edition or VS Test edition or something like that: See VS 2008 Team System Test Edition)

From the menus, choose File->New->Project Test Documents->Test Project. If you don’t see the option, you probably don’t have the right version of VS. You can even open your existing VS solution, right click on the solution at the top of the Solution Explorer, then choose Add->New->Project. This way, your test code can be in the same solution as your target code.

You can change the default test language (VB or C#) from Tools->Options->Test Tools->Test Project

From the menus, choose Test->Windows->Test List Editor. I like to have that window dockable: right click on the tab and choose Dockable, then dock it where you like.

Open UnitTest1.vb from the solution explorer and you’ll see this code:

 Public Sub TestMethod1()
        ' TODO: Add test logic here
    End Sub

Full Article

Microsoft, VS, Visual Studio, Framework, Code, Testing, VB, Visual Basic