Closed seanong-athena closed 1 year ago
The purpose of using mocks is to avoid interaction with the database.
Unfortunately, the only way to generate the precise 'SObject row was retrieved via SOQL without querying the requested field' when accessing an SObject is to have retrieved it from the database. Pure unit tests are not a substitute/replacement for some amount of integration test coverage -- you should be testing for the above message in one of your integration tests.
We have no plans to emulate that logic in the mocking framework as it would be nearly impossible to do.
I implemented a selector class:
I then used the selector in a method, which will fail as expected with the error
SObject row was retrieved via SOQL without querying the requested field
In a test class, I write the test using the Salesforce standard way (using DML) and it fails as expected:
However, if I write the test using apex mocks, the test will run successfully when it is hoped that it will fail:
Feature request: When mocking selectors, the output will only contain the fields retrieved by the query. I know that there is a method
SObject.getPopulatedFieldsAsMap()
and I wonder if this could be incorporated somehow.