Salesforce Testing Explained.
1. What is Salesforce Testing?
Salesforce testing is the process of verifying a Salesforce customization and configuration with the purpose of identifying any errors, gaps or missing requirements versus the actual requirement. Testing is important to make sure that the delivered functionality meets the user requirement. Testing helps to identify and fixe any possible bugs in the application before it goes live.
2. Salesforce Testing Life Cycle
There are five stages of Testing Life Cycle:
- Requirement Gathering – Understand the business requirements of the application being built.
- Test Planning – Define test strategy, objectives and test plan
- Test Environment Setup – Get access to a Salesforce sandbox and setup test data.
- Test Execution – Execute the test cases and document any bugs identified.
- Test Closure – Document test summary once all test cases has been executed and identified defects fixed.
3. Types of Salesforce Testing
Salesforce testing is broadly categorized into two types:
- Functional testing
- Non-functional testing
Testing can be Manual or Automated.
4. Functional Testing
Functional Testing tests whether the application being developed meets the functional requirements captured in the requirement document or User Stories. Functional Testing can be divided into following components:
- Unit Testing – Individual units of code and configurations are testing to determine whether they meeting the expected requirement.
- Integration Testing – Individual modules are combined and tested as a group.
- System Testing – End to end testing of complete integrated system to evaluate systems compliance with the specified requirements.
- User Acceptance Testing – Testing performed by end user or customers.
5. Non-Functional Testing
Non-Functional Testing evaluates the performance, usability and reliability of the application. Non-Functional Testing can be divided into following components.
- Performance – Testing to determine how a system performs in terms of responsiveness and stability under a particular workload.
- Security – Testing intended to reveal flaws in the security mechanisms of an information system that protect data and maintain functionality as intended
- Usability – Testing to evaluate how easy is it to use the application from end user perspective.
- Compatibility – Testing to ensure the application’s compatibility with different computing environment.
6. Salesforce Testing Best Practices
Some of the Salesforce Testing Best Practices are:
- Testing using different Profiles and Roles – Tester should login as different users to test the application and some of the features may not behave the same when testing using a non System Admin User.
- Appropriate Sandbox – System and Performance Testing should be conducted in Full Copy Sandbox
- Enabled Debug Logs – Testers should enable debug logs while testing because some of the errors may not show up on screen but are logged in debug logs. Such errors should also be logged as a Bug and fixed accordingly.
- Setup Apex Exception Email – Testers should add their email in Apex Exception Email because some of the errors may not show up on screen but they will be notified in the email. Such errors should also be logged as a Bug and fixed accordingly.
7. Apex Test Class Best Practices
Some the important Apex Test Class Best Practices are:
- Aim for 95% Code Coverage – Although Salesforce requires 75% it is a best practice to have more than 95% code coverage.
- Use System.assert – Use System.assert method to validate that code is behaving as expected.
- Use RunAs – Use RunAs method to test your application using different user contexts.
- Bulk Testing – Use at-least 20 records in your tests.
- Test Data – Create test data in test classes instead of using actual org’s data for testing.
- Use startTest and stopTest – Use startTest and stopTest in the test methods.
- Do not use SeeAllData.
- For testing Web Services leverage Mock Testing Framework.
- Use @testSetup for creating test data.
- Use Test Factory pattern to create test data instead of creating test data for individual Test Classes.
8. Final Thoughts
- It is very important to prioritise testing customisations over OOB Salesforce features.
- Testers must user different profiles to makes sure that functionality is testes a business users instead of System Admin.
- Salesforce Automation Testing tools such as Selenium, Quick Test Professional (QTP) can be used to automate some of the frequently tested scenarios.
9. Additional Resources