O'Reilly logo

Professional ASP.NET MVC 3 by K. Scott Allen, Brad Wilson, Phil Haack, Jon Galloway

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

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

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