Understanding how ApexMocks works

The whenCarStartCalledDashboardAndEngineInitialised unit test method in the CarTestApexMocksDemo test class uses the ApexMocks library. The structure of this unit test is similar to those we have looked at so far in this chapter. It creates the mocks, runs the method to test, and asserts the results.

The big difference is that you do not need to write any code for classes you wish to mock. Instead, you use the ApexMocks framework to configure your mock responses and to assert what methods were recorded. Then, through its integration with the Apex Stub API, it creates a stub that wraps itself around any class you wish to mock.

The main class within the ApexMocks framework is fflib_ApexMocks. This class implements ...

Get Salesforce Lightning Platform Enterprise Architecture - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.