Why should you test your code on your Salesforce Org?
If you are running custom code to power business critical processes on Salesforce, it is just plain reckless to assume you don’t need testing. It ensures: quality, reliability, and performance of that code. You simply cannot guarantee these things with trial and error. Unfortunately most businesses do just that when it comes to software testing. Try to do as much as possible and call a Salesforce Partner when there’s an error.
Common Types of Testing
Well let first talk about how tests can be run:
- Manual: Tests performed by personnel such as QA Engineers/Users.
- Automated: Tests run by scripts or computers.
Certain types of tests, like unit tests, lend themselves very well to automation. Where others, like UI testing, often need users to perform the testing. If you can get a decent amount of code coverage with automated tests it is more reliable and cost effective to have your developers write automated tests as part of the coding process.
A robust testing strategy might favor certain types of tests, but it certainly does not exclude any. One type of testing is not better than another, they are all important in their own way. Let’s take a look at some common types of testing and terms related to testing:
- Unit Testing: a test that tests an individual unit or function of a program.
- Integration Testing: a test that tests the interaction of two or more units.
- UI Testing: a test related to the user interface of the application.
- Load Testing: a test that measures how much traffic the application can handle before failing.
- User Acceptance Testing: when the application is tested by actual users, often in small groups.
- Accessibility Testing: testing that ensures usability for users with disabilities.
- Continuous Integration: the process of continuously merging code, running tests, and refreshing developer copies of the code base. A modern development practice.
What type of testing should you use for Salesforce?
Martin Fowler has put forth the concept of the test pyramid, as tests become more manual they are more expensive. Therefore, we should cover our software as much as possible with automated tests. In addition to being more cost effective, automated tests are also more predictable and reliable. Let’s take the mindset that automated testing is preferable when looking at what tests should be done to your Salesforce org.
So, what specific tests should be done for your Salesforce org? Well it depends on what you are developing, but there are three main areas of code on Salesforce that should be covered with testing. Of the orgs I’ve seen, many orgs don’t do anything beyond Apex testing. And even then the Apex testing just covers lines of code, it doesn’t actually test software. But more on that later.
Here are the three main areas that should be covered with automated tests:
1. Apex Code: Triggers, Classes, etc.
2. Custom Lightning Code: Components, Apps
3. Visual Force Code
What type of tests should you use in these areas? There are a lot of different coding styles. For example, if you write very functional code, you will probably be pretty well covered with mostly unit tests. But in most cases you will need an appropriate mix of the test types.
If the ultimate goal is writing reliable software, testing alone will not be sufficient to achieve that goal. It has to be a mindset of development. You want to prevent and avoid bugs as early as possible. Tools like linters, style guidelines, and markup validators are also important in a proper testing strategy.
How to develop a Robust Testing Strategy for the Salesforce Platform
Formulating a proper testing strategy on the Salesforce Platform is no different than any other platform. If you are wondering where to start, here are some suggested reads and tutorials for writing great software and getting the right mindset in addition to the skills:
- Refactoring by Martin Fowler
- Code Complete by Steve McConnell
- Learn SFDX — Udemy Course (Free with code: EIGENX)
- Learn Git — CodeCademy
- Testing Apex — Salesforce.com
If you’ve heard anything about SFDX, you’ve likely seen continuous integration mentioned with it.
One of the things we aim for at Eigen X is a proper software development mindset. There’s more to writing strong software than just test coverage. When developing custom software on the Salesforce Platform, we’ll implement an appropriate strategy based on your needs for ensuring reliability, quality, and performance of code on your Salesforce Org. Too often on this platform people test the wrong things or avoid testing entirely.
If you have any questions about testing on the Salesforce Platform, feel free to reach out to us on here, Twitter, or through email at info@eigenx.com.