Force.com Best Practices - Unit Testing

Unit Testing



·         Use a consistent naming convention including "Test" and the name of the class being tested (e.g., Test_AccountTrigger)
·         Test classes should use the @isTest annotation
·         Test methods should craete all data needed for the method and not rely on data currently in the Org.
·         Use System.assert liberally to prove that code behaves as expected.
·         Test each branch of conditional logic
·         Write test methods that both pass and fail for certain conditions and test for boundary conditions.
·         Test triggers to process 200 records - make sure your code is "bulkified" for 200 records and doesn't throw the dreaded "Too many SOQL queries: 21" exception.
·         When testing for governor limits, use Test.startTest and Test.stopTest and the Limit class instead of hard-coding governor limits.
·         Use System.runAs() to execute code as a specific user to test for sharing rules (but not CRUD or FLS permissions)
·         Execute tests with the Force.com IDE and not the salesforce.com UI. We've seen misleading code coverage results when running from the salesforce.com UI.
·         Run the Force.com Security Source Scanner to test your Org for a number of security and code quality issues (e.g., Cross Site Scripting, Access Control Issues, Frame Spoofing)

Force.com Best Practices - Unit Testing Force.com Best Practices - Unit Testing Reviewed by dasfrogpractice on 06:14 Rating: 5

No comments:

Theme images by mariusFM77. Powered by Blogger.
Youtube Channel Image
Dasfrog Subscribe To watch more Salesforce Training
Subscribe