Best Practices for Test Script writing


@isTest
private class Test_class {
code_block;
}
  • Test methods are declared with the following syntax:

static testMethod void test_name() {
code_block;
}
  • When you create a test method,
    • Use static
    • Use testMethod keyword
    • Use void return type
    • No any arguments
    • No data changes performed in a test method
    • Don’t send emails
  • The key methods to use in your unit tests are the system.assert() methods:
    • System.assert(condition)
    • System.assertEquals(x,y)
    • System.assertNotEquals(x,y)
  • Test methods cannot be used to test Web service callouts. Web service callouts are asynchronous, while unit tests are synchronous.
  • Salesforce.com recommends that you write tests for the following;
    • Single action
    • Bulk action
    • Positive behavior
    • Negative behavior
    • Restricted user
  •  
Best Practice for writing Test Classes
·Write fully portable tests ·        
Don’t use production data in your tests ·  
Test expected behavior first, then test unexpected behavior ·        
If you find a bug, write a test to expose it before you fix it ·        
Shoot for 100% coverage ·        
Don’t rely on Today() ·        
Put your tests on the controller and class, not in separate classes

Comments

Popular Posts