Chapter 12

Unit Testing

— By Brad Wilson

What's In This Chapter?

  • Understanding unit testing and Test-Driven-development
  • Building a unit test project
  • Good advice for unit testing your ASP.NET MVC application

Unit testing and developing testable software have become recognized as an essential element in the software quality process. Most professional developers practice some form of unit testing in their daily job. Test-Driven Development (TDD) is a style of writing unit tests where the developer writes a test before writing any production code. Using TDD allows the developer to evolve the design in an organic way, while still gaining the quality and regression testing benefits of unit tests. ASP.NET MVC was written with unit testing in mind. This chapter focuses on how unit testing (and TDD in particular) applies to ASP.NET MVC.

For users who have never practiced unit testing or TDD, we have included a brief introduction to unit testing and TDD as a form of encouragement to seek out more in-depth information on the practices. Unit testing is a very large subject. This introduction should serve you well as a guide as to whether unit testing and TDD are something you want to do further research on.

In prior editions of this book, the unit testing chapter was focused heavily on the mechanics of unit testing with a lot of sample code. In this edition, we've decided to shift the focus to providing a set of real-world tips and tricks as it applies to unit testing the specific parts ...

Get Professional ASP.NET MVC 3 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.