Introduction to Testing in Salesforce

Sharing is Caring

Automated testing confirms whether a piece of particular code is working correctly. And, its no secret, that writing automated tests helps decrease bugs and locate existing bugs.

Why write test methods?

  1. Test Methods are required to deploy Apex to a production environment. In Salesforce, all classes must have at least 75% code coverage.
  2. If you are releasing an app onto Salesforce’s Force.com AppExchange they are required.
  3. Test methods provide test automation which can enable greater QA efficiency, and can help avoid creating future bugs in the maintenance stage.
  4. They provide a very easy way of doing automated regression testing.

Within the development community there are a lot of debates about how much testing is required.

Types of Tests
Unit Tests test the least lines of code; but reduce external dependencies by using mock objects.

Unit Tests can be really challenging to implement in really interconnected code bases.

Integration Testing covers how the different “units” interact together.

Functional Tests

Some Best Practices

  • Don’t Depend on Pre-Existing Data
  • use System.runAs() methods to verify test users can find records that were shared with apex
  • Mimic VisualForce page interactions by explicity calling methods
Sharing is Caring

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.