In this section, we will briefly test the test controller. In all different types of automated tests, we only care about one type at the moment: unit testing ).
Unit testing is a small script-based test, which is usually written in the same language as the product code. They establish and practice the functions of a single component in the form of isolation from the rest of the system to verify that it works correctly. As applications grow, the number of unit tests increases. Applications with thousands of tests are common and can be executed at any time to verify bugs not introduced in the code library.
To ensure that unit tests run quickly, it is important not to allow them to call external processes. When conducting unit tests on the Controller code, various dependencies should be simulated so that the only running product code is the controller itself. To make it possible, it is important to design a controller in this way: any external dependency can be easily exchanged externally (such as database or web service calls ).
To effectively test the guestbookcontroller, we need to make some modifications that consider testability. But before doing this, let's take a look at the default unit test project, which is part of ASP. net mvc.
1. Use provided test items
By default, when creating a new ASP. net mvc project, vs provides an option to create a unit test project.
Knowledge Point 4-2: unit test Introduction