Unit Testing
Unit testing is a key technique used by developers to maintain a healthy and robust code base. This 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 is the current usage of that method safe from regression but also future usage is protected. This frees the developer to focus on other 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 the Lightning Platform. 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 dependency, such as a class method or component...