ApexMocks and Apex Enterprise Patterns
As we saw earlier, the supporting library or Apex Enterprise patterns provides methods that provide a Dependency Injection facility through the factories in the Application
class. This facility is also compatible with the use of ApexMocks and Apex Stub API. The following sections contain examples of the use of ApexMocks to unit test the layers within the application architecture introduced in earlier chapters.
Unit Testing a Controller Method
The following test can be found in the RaceControllerTest
class and demonstrates how to mock a service layer class:
@IsTest private static void whenAwardPointsCalledIdPassedToService() { fflib_ApexMocks mocks = new fflib_ApexMocks(); // Given RaceServiceImpl mockService ...
Get Force.com Enterprise Architecture - Second 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.