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

Author: Brian Cline

Brian is a programmer living in Niagara Falls with ten years of development experience. He is passionate about automation, business process re-engineering, and gamification. For the last six years or so, he has been working with Salesforce and JavaScript.

Related Posts

Sharing is Caring