-
Notifications
You must be signed in to change notification settings - Fork 53
Test Data Builder Field Injection
John Storey edited this page May 16, 2020
·
4 revisions
A downstream package has added a field value requirement, as in the field is required or must have a certain value or range of values, etc. In this case, the Marketing implementation has declared the "Slogan" field on the Account is required. If DML-based tests are necessary, peer or upstream packages cannot be aware of this requirement, and downstream packages should not be troubled with irrelevant requirements.
Reading from a custom metadata type, a TestDataSupplementer, existing in the core implementation, can dynamically call implementation appropriate classes that refine test data in order to alleviate data-requirement rules.
- A unit test creates an instance of an Account and a passes it to the TestDataSupplementer.
- During instantiation, the TestDataSupplementer reads the TestDataSupplementer custom metadata type for records related to the Account.
- The supplementer then pass the test's data to the specified classes in the custom metadata.
- The Slogan field is populated after the test class calls the TestDataSupplementer, although the test is unaware of any such requirement. Note: This project does not in fact define the Slogan field as required, but the test does not populate the field, although the assertion validates its existence.