When we talk about software testing, we are referring to a whole host of different activities, including unit testing, acceptance testing, exploratory testing, performance testing, and scalability testing. To set the stage for this chapter, it's helpful to start with a shared understanding of what is meant by unit testing — the subject of this section.
Most developers have some exposure to unit testing and some opinion on what works best. In our experience, the following attributes tend to be present in most long-term successful unit testing:
The following sections examine each of these rules and how they impact the way you write unit tests.
When writing a unit test, you're often looking for the smallest piece of functionality that you can reasonably test. In an object-oriented language like C#, this usually means nothing larger than a class, and in most cases, you're testing a single method of a class. The reason to test small pieces of code is that it allows you to write simple tests. These tests should be easy to understand so that you can verify that you're accurately testing what you intended.
Source code is read far more often than it is written; this is especially important in ...