Newer Version Available
Mock SOQL Tests for Data Cloud Data Model Objects
Create mock test classes by extending the new System.SoqlStubProvider class and overriding the handleSoqlQuery() class method. Create DMO instances using either Test.createStubQueryRow() or Test.createStubQueryRows(). Register the mock provider in the test using Test.createSoqlStub() and execute the test code.
The SOQL query must be against a DMO or an external object, either directly with a FROM clause or via a subquery. If you query against a stubbed object type that doesn’t include a DMO or an external object, the error Stubbed query invocations can't be used without a participating query stub set. is thrown.
These features are not allowed within a stub implementation:
- SOQL
- SOSL
- Callouts
- Future methods
- Queueable Jobs
- Batch Jobs
- DML
- Platform Events
This example shows a mock test class for the SkyMilesForBusinessOptInController class.