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.



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.



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 ...

Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD 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.