O'Reilly logo

Professional Test-Driven Development with C#: Developing Real World Applications with TDD by Jeff McWherter, James Bender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A QUICK EXAMPLE OF THE TDD APPROACH

The following exercise takes you through an example of what it's like to develop a feature for a system using TDD. For this example, imagine you have been asked to create a feature that counts occurrences of a character in a string. Assume that you are working in an existing solution, with an existing project structure, but the class you'll implement this method on does not exist. Also assume for this example that your unit-testing frameworks have been referenced in your project. Don't worry; I cover how to do this in Chapter 6. Currently, the solution looks like Figure 1-1.

images

FIGURE 1-1

The ChapterOne.UnitTests project will contain our unit tests. The ChapterOneExample.Utilities project will be where our completed class will be placed. The first step is to create a class in our unit test project that will contain our unit tests, as shown in Figure 1-2.

images

FIGURE 1-2

You have a variety of ways to arrange your unit test classes within your unit test project. Some developers prefer to place each test class in a separate code file. Some developers like to create a code file for all the test classes for a specific feature. A more common approach, which is the one taken here, is to create a code file class for all the unit test classes for a specific section ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required