Visual Studio 2010: Test Driven Development
Visual Studio 2010 brings with it several enhancements to help cut development friction and enable the developer to focus on the task at hand: writing high-quality code. In the following exercises we'll highlight several of the new features that the TDD developer can use to enhance his/her development cadence. Visual Studio helps your cadence by cutting the number of keystrokes to accomplish frequently performed tasks, speeds navigation through your solution, and enables you to use test frameworks other than MSTest.
Test Driven Development (TDD), also frequently referred to as Test Driven Design, is a development methodology where developers create software by first writing a unit test, then writing the actual system code to make the unit test pass. The unit test can be viewed as a small specification around how the system should behave; writing it first helps the developer to focus on only writing enough code to make the test pass, thereby helping ensure a tight, lightweight system which is specifically focused meeting on the documented requirements.
TDD follows a cadence of “Red, Green, Refactor.” Red refers to the visual display of a failing test – the test you write first will not pass because you have not yet written any code for it. Green refers to the step of writing just enough code in your system to make your unit test pass – your test runner’s UI will now show that test passing with a green icon. Refactor refers to the step of refactoring your code so it is tighter, cleaner, and more flexible. This cycle is repeated constantly throughout a TDD developer’s workday.
This lab is not meant to teach you how to work with TDD; instead, it is intended to highlight Visual Studio 2010’s support for working in TDD. If you are interested in learning more about the TDD methodology and its benefits then you should look to the following books as a starting point:Test Driven Development in Microsoft .NET by James Newkirk and Alexei Voronstov, ISBN 0735619484Pragmatic Unit Testing in C# with NUnit, 2nd Edition by Andy Hunt, Dave Thomas, and Matt Hargett, ISBN 0977616673
A critical aspect of TDD is developer cadence. Getting into a productive development rhythm (the elusive “zone”) involves having the right mindset, but also working with tools that assist the developer in working rapidly and with as little friction as possible.
Visual Studio 2010 brings with it several enhancements to help cut development friction and enable the developer to focus on the task: writing high-quality code. In the following exercises, you will learn several of the new features that the TDD developer can use to enhance his/her development cadence. VS10 helps your cadence by cutting the number of keystrokes to accomplish frequently performed tasks, speeds navigation through your solution, and enables you to use test frameworks other than MSTest.
To demonstrate the new features you will build an implementation of a stack in a test-first manner, showing how tests drive the design and implementation of a SimpleStack class.
In computer science, a stack is an abstract data type and data structure based on the principle of Last In First Out (LIFO).If you are unfamiliar with the concept of a stack as a data structure, or just need a quick refresher, please see the full Wikipedia article for a more thorough definition.
In this Hands-On Lab, you will learn how to:
You must have the following items to complete this lab:
All the requisites for this lab are verified using the Configuration Wizard. To make sure that everything is correctly configured, follow these steps:
To perform the setup steps you need to run the scripts in a command window with administrator privileges.
This Hands-On Lab comprises the following exercises:
Estimated time to complete this lab: 60 minutes.
This lab shows code examples in both C# and VB.NET; however, screen shots reflect only C# actions. Each action shown in the screenshots has a similar set of steps for VB.NET.