Mock SOQL Tests for Data 360 Data Model Objects
You can mock SOQL query responses for Data 360 data model objects (DMOs) in Apex testing by using the new SOQL stub methods and a new test class. Use static or dynamic SOQL queries against DMOs and return mock records in a testing context.
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.
Apex governor limits apply to the stubbed records.
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.
See Also