The Meaning of Unit Testing and Test-Driven Development
When we talk about software testing, this refers to a whole host of different kinds of testing that can take place, such as unit testing, acceptance testing, exploratory testing, performance testing, and scalability testing, to name several. 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.
Defining Unit Testing
You can practice unit testing in a variety of ways, and everybody who has done it tends to have an opinion on how best to go about it. In our experience, the following attributes tend to be present in most long-term successful unit testing:
- Testing small pieces of production code (“units”)
- Testing in isolation from the rest of the production code
- Testing only public endpoints
- Running the tests gets an automated pass/fail result
Each of these rules and how they impact the way you write unit tests are examined in the following sections.
Testing Small Pieces of Code
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 use of testing small pieces of code is that it allows you to quickly write simple tests. The tests need to be easy to understand so that you can verify that you're accurately testing what you ...
Get Professional ASP.NET MVC 3 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.