I need to write a test class for trigger on a standard object. opportunity.
The plan is package the trigger and test class as a free app so users can re-use the component.
As we all know the test coverages are environment dependent. They are dependent on factors like
(1) Custom Mandatory fields, (2) Custom Validation rules & (3) other custom triggers on the object
Are these best practices around creating test class for standard object which can have a good coverage irrespective of the test environment ?
Attribution to: Manisha
Possible Suggestion/Solution #1
I think their are couple of ways to reduce env. dependency, like
- Use isTest(SeeAllData=false) for all test classes before API v23, afterwards this is default setting on test cases. This wil make sure no dependency on org data and you create clean test data on own. (click here for more details)
- Use SmartFactory, it assigns reasonable defaults to new custom + required fields in other orgs. So chances of failure are relatively reduced. Check more on github repos: https://github.com/mbotos/SmartFactory-for-Force.com
Attribution to: Abhinav Gupta
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1331