ASP.NET MVC 3 Testing

Version: 1.1.0

Description

Testing an application is an automated way of verifying it is always behaving the way it is supposed to. That way, you can later make changes to the code and refactor components without breaking something else somewhere in the application.This Lab will take you through the process of testing controllers in an ASP.NET MVC application, used to verify that actions are working properly. In this Hands-on Lab, each test is independent from the others, but instead of stubs or mocks, you will be testing the controllers against a well-known database. If needed, that database will be protected by transactions and its initial state will be copied for each test execution, making sure that each test runs with a controlled data set.

Overview

Note:
This Hands-on Lab assumes you have basic knowledge of ASP.NET MVC. If you have not used ASP.NET MVC before, we recommend you to go over ASP.NET MVC Fundamentals Hand-on Lab.

Testing an application is an automated way of verifying it is always behaving the way it is supposed to. That way, you can later make changes to the code and refactor components without breaking something else somewhere in the application.

This Lab will take you through the process of testing controllers in an ASP.NET MVC application, used to verify that actions are working properly.

Unit testing is a particular method where each test isolates and verifies a single part of the application, in an isolated way, with the possibility of automating tests. A unit test is the smallest testable part of an application. In procedural programming may be a procedure, in object oriented programming, a method.

Unit tests are created by programmers, and their objective is to isolate each part of a program and verify that individual parts are correct. Typically in unit testing, substitutes like method stubs, mock objects, fakes and test harnesses can be used to guarantee that isolation.

In this Hands-on Lab, each test is independent from the others, but instead of stubs or mocks, you will be testing the controllers against a well-known database. If needed, that database will be protected by transactions and its initial state will be copied for each test execution, making sure that each test runs with a controlled data set.

You will first focus on testing simple controller actions, then CRUD actions and finally the shopping cart actions implemented in the ASP.NET MVC Membership, Authorization & Store Checkout Hands-on Lab.

Note:
Disclaimer: Test Driven Development (TDD) is a software development process where failing unit tests that define an improvement/function are written before the actual code that implements that behavior. The test passes after the implementation is done according to the test specifications. Finally, the code is refactored to match standards, improve efficiency, etc.

Since you will be testing the MVC Music Store code built throughout the past Hands-on labs, you will not be strictly practicing TDD. Else, you will create tests to verify the behavior of already-written code.