Chapter 12. Unit Testing
Unit testing is a key technique used by developers to maintain a healthy and robust code base. The approach allows developers to write smaller tests that invoke more varied permutations of a given method or a unit of code. Treating each method as a distinct testable piece of code means that not only current usage of that method is safer from regression, future usage is protected as well. It frees the developer to focus on more permutations, such as error scenarios and parameter values beyond those currently in use.
Unit testing is different from integration testing where many method invocations are tested as a part of an overall business process. Both have a place on Force.com. In this chapter we will explore when to use one over the other.
To understand how to adopt unit testing we first need to understand dependency injection. This is the ability to dynamically substitute the behavior of a dependent class' s methods with test or stub behavior. Using...