Working with Visual Studio Team Edition for Testers

Test drive your code using VSTET to reduce post deployment bugs.

by Joydip Kanjilal

Rituraj Singh

Dec 19, 2007

Page 1 of 3

oorly-written code and nonconformance to coding standards may get an application ready to ship a little more quickly, but often becomes a nightmare after application deployment. The answer is, of course, properly planned code testing that parallels your development cycle. Test Driven Development (TDD) simplifies development and reduces bugs and complexity by driving the development life cycle of your project using predefined tests. Initially, implementing TDD was difficult, but as it gains favor among development teams, it's also gaining support from major tools vendors. In this article you'll see how to use Visual Studio Team Edition for Testers (VSTET) to design and implement unit tests and web tests in your applications.

In the book "Practical TDD and Acceptance TDD for Java Developers," Lasse Koskela writes, "TDD is a way of programming that encourages good design and is a disciplined process that helps us avoid programming errors. TDD does so by making us write small, automated tests, which eventually build up a very effective alarm system for protecting our code from regression. You cannot add quality into software after the fact, and the short development cycle that TDD promotes is well geared toward writing high-quality code from the start."

You can read more about TDD on MSDN, but briefly, TDD states that you drive the development from the tests. Therefore, you need to write the tests first, before you write even a single line of code, and then use those tests to ensure your code meets the requirements. For example, suppose you wanted to write a method to calculate factorials. First, you'd write a test that would ascertain whether the return value from your factorial-calculation method is a valid factorial:

Assert is a static class available in the Microsoft.VisualStudio.TestTools.UnitTesting namespace. You use the Assert.AreEqual method to test whether two specified values are equal—it returns false when the two values are not equal. With the test in place, you can code the factorial-calculation method:

Now that you have a basic understanding of TDD, you can explore what VSTET offers for developers using TDD—VSTET provides almost everything you need to test an application within the VS 2005 IDE. Almost, because of the limitations mentioned toward the end of this article. VSTET lets users create, manage, edit and run tests. It even allows you to store the test results.

Types of testing supported by VSTET
VSTET supports the following test types:

Unit Tests: As the name implies, this type of test is intended to test a specific unit of your code. VSTET ships with a built-in unit testing framework called Microsoft.VisualStudio.QualityTools.UnitTestFramework, which includes a variety of namespaces, classes, and interfaces that you can use to write, execute, and report on unit tests.

Web Tests: A Web Test lets you record sequences of user interactions and navigation between pages in a web application. You can then reuse these recordings to test your application.

Manual Tests: This is the simplest type of testing. You need to execute the application and run the test cases one after the other to ensure that the preconditions, post conditions and the results actually meet your requirements as defined in the test cases.

Load Tests: You use load tests to run unit tests and/or web tests with some predefined parameters for performance testing.

Ordered Tests: This type consists of a list of tests intended to run in a specific order. Note that you cannot include a load test in the ordered test list.

Generic Tests: This type lets you use third-party tools or executables as tests in VSTET. For example, you could plug in existing tests from other sources or a custom executable that ran tests into VSTET using this type of test. After you wrap your existing test, executable, or third-party tool inside a generic test, VSTET treats it like any other test type.