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
Reviewed by dasfrogpractice
on
06:14
Rating:

No comments: