Summary
In this chapter, we dealt with the importance of testing our Apex code and how we can improve the quality and integrity of our tests. Testing is a key part of the software development life cycle, and writing clear and well-structured tests that validate assumptions and outcomes through assertions is extremely important in providing confidence in your system.
We also saw how we can improve the creation of test data for our tests in a number of ways. The largest performance problem for Apex tests is the repeated creation of data in different unit tests, as the system must run through the save order of execution multiple times, taking up time and governor resources. By separating our test data into a factory, we can ensure that data is created in a consistent manner and save ourselves additional rework should the code need updating to accommodate new required fields and processing. Calling our test data creation from a method annotated by @TestSetup
ensures that the data is...