Chapter 9. Testing ASP.NET MVC Applications

The ASP.NET MVC framework has been developed to be testable out-of-the-box. After having learned in the previous chapter what unit testing is and how to test applications, in this chapter you apply these concepts together with the ASP.NET MVC-specific features made to facilitate testing.

In the chapter, you learn:

  • How to create a new testing project for an ASP.NET MVC application

  • How to test controllers' actions and routes

  • How the ASP.NET MVC framework facilitates testing

  • How to test an end-to-end application

  • A bit of TDD approach

Creating a Test Project for ASP.NET MVC

Every ASP.NET MVC application should have a companion test project, so the project template for this process is super. When you create an ASP.NET MVC Web application, as soon as you click the OK button, another dialog pops up (see Figure 9-1), asking you whether you want to create a unit test project for the application. In this dialog, you can choose the name of the test project; by default, it's named like the MVC project name dot Tests (for example mvcapplication.Tests) and the testing framework you want to use to create the tests with. With the installation, there is only the Visual Studio Unit Test template, which uses MSTest, but you can add other testing frameworks if you like. (In Figure 9-1 MbUnit v3 is shown.)

Figure 9-1

Figure 9.1. Figure 9-1

If you choose Yes, a new project will be ...

Get Beginning ASP.NET MVC 1.0 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.