Chapter 13

Unit Testing

What's In This Chapter?

  • Understanding unit testing and test-driven development
  • Building a unit test project
  • Advice for unit testing your ASP.NET MVC application

Unit testing and developing testable software have become recognized as essential elements in the software quality process. Most professional developers practice some form of unit testing in their daily jobs. Test-driven development (TDD) is a style of writing unit tests where the developer writes a test before writing any production code. 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 as a guide to whether unit testing and TDD are something you want to research further.

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. I've decided to shift the focus to providing a set of real-world tips and tricks that apply to unit testing the specific parts of your ASP.NET MVC application. The second half of this chapter is ...

Get Professional ASP.NET MVC 4 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.