Skip to main content
Use of test data factories

Ensure test data are created using factory methods, to limit the code maintenance needed when changing validation rules.

Lorenzo Frattini avatar
Written by Lorenzo Frattini
Updated over a week ago

Rationale

Test methods should not create data instances directly as it puts tests at risk of breaking if new validation rules are added in the future. As a best practice, test data instances should be created in centralized test data factories, so that the introduction of new validation rules don't break existing test methods.
This rule detects circumstances where instances of data objects are created directly, introducing the problem.

Scope 

  • Apex test methods

  • SObject definitions

Did this answer your question?