A mocking framework for true unit testing in Salesforce Apex, inspired by Mockito with Stub API support.
FFLib ApexMocks is a mocking framework for the Salesforce Lightning Apex language that enables true unit testing by allowing developers to verify behavior and stub dependencies. It solves the problem of testing Apex code in isolation without requiring database interactions or external service calls. Inspired by Mockito, it integrates with Salesforce's Stub API to generate dynamic mock objects at runtime.
Salesforce developers and architects building enterprise applications on the Lightning Platform who need to write robust, maintainable unit tests following dependency injection patterns.
Developers choose ApexMocks because it provides a familiar, Mockito-like API for Apex, supports behavior verification and stubbing, and integrates seamlessly with Salesforce's Stub API. Its detailed error messages and utilities for mocking read-only fields make it a comprehensive solution for unit testing in the Salesforce ecosystem.
An Apex mocking framework for true unit testing in Salesforce, with Stub API support
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows verification of method calls with specific arguments and counts, throwing detailed exceptions on mismatches, as shown in the README's verify() example with clear error messages.
Enables stubbing method returns and exceptions using when() and thenReturn(), creating controlled test environments without external dependencies, demonstrated in the stubbing examples.
Leverages Salesforce's native Stub API to generate dynamic mock objects at runtime, ensuring seamless compatibility with the Lightning Platform, as highlighted in the documentation.
Provides utilities like fflib_ApexMocksUtils.setReadOnlyFields() to mock read-only SObject fields such as formula fields, which is unique to Salesforce testing needs.
Requires projects to adopt dependency injection patterns, which can be a significant architectural shift and adds complexity for teams not already using it, as assumed in the README examples.
Documentation is scattered across multiple external blog posts and resources, making it difficult to find comprehensive, up-to-date guidance without navigating disparate links.
Assumes familiarity with mocking concepts and Salesforce's Stub API, posing challenges for developers new to unit testing in Apex, despite the Mockito inspiration.