Chapter 2. Test-Driven Development in .NET—By Example

In this chapter, we’ll demonstrate how to implement a Stack using Test-Driven Development (TDD). We have found that the best way to understand TDD is to see it practiced and follow along step by step. The following are the steps we used to build a Stack using this method.

The Task

The task is to implement an unbounded Stack, which is a data structure in which access is restricted to the most recently inserted item.

Note

An unbounded Stack doesn’t have to be presized, and you can insert an unlimited number of elements onto it.

The operations include Push, Pop, Top, and IsEmpty. The Push function inserts an element onto the top of the Stack. The Pop function removes the topmost element and returns ...

Get Test-Driven Development in Microsoft® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.