Unit tests are mandatory for all Apex code, including Visualforce controllers but not the pages themselves. Your application code must have at least 75% test coverage before it can be deployed to a production environment.
The mechanics of writing unit tests for controllers is similar to that of triggers, with some additional system methods for test setup. But the strategy for testing controllers is unique, because controller code normally relies on the Web browser to drive it.
Listing 6.19 provides an example of the test setup code. It starts by creating an instance of the controller class and getting a reference to the Visualforce page to test. This is a
PageReference instance, created by passing the page name as an argument. The ...