In this blog post, we will learn to write unit tests for various MVC controller’s behaviors, such as view’s return types, redirecting to different actions etc. Specifically, we’ll cover writing Unit Tests for:
- ViewData of the Controller
- TempData of the Controller
- ViewBag of the Controller
- View of the Controller
Let’s get started!
Creating the MVC Project under Test
Let us go ahead and create a MVC project under Test. To keep things simpler, I have selected ”No Authentication” for the project. In this example we are going to write unit tests for the HomeController. The HomeController contains two action methods:
- Index
- Details
We are going to write tests for these actions. The HomeController contains code as shown here:
Leave a Reply