Testing From The Trenches - Salesforce1 World Tour 2014

Preview:

DESCRIPTION

As the Salesforce1 World Tour moves to London on May 22nd 2014, Force.com MVP's Chris Lewis and Simon Lawrence present the 15:00 Developer Stage Session on Testing Best Practices for the Salesforce.com Platform.

Citation preview

Testing From The TrenchesMay 22nd, 2014

Christopher Alun Lewis

Advanced Developer

Force.com MVP

A Developers Perspective

Simon Lawrence

Certified Developer

Force.com MVP

http://www.slideshare.net/SimonLawrence4

Why Do We Test?• Testing is required by Salesforce.com to release code to production

environments

• Regression Protection Against Future Changes

• Salesforce make 3 Platform Releases a Year

• Residing in a Multi-Tenancy Environment

• To Rid Your Systems of Bugs

Testing on Salesforce

Our 5 Top Tips for Testing

#1 Always Include Assertions

• These are what we call “Skeleton Tests”

• Other than avoiding exceptions, provide almost no use

• Missing a great opportunity to provide feedback on future

failure scenarios

#1 Always Include AssertionsThe Code

#1 Always Include AssertionsThe Criminal Test

#1 Always Include AssertionsThe Correct Test

#2 Remember your Batch Scenarios

• Your code may need to process large collections objects,

ensure that your tests cover this

• A serious consideration for testing your system’s ability to

operate within the governor limits

#2 Remember your Batch ScenariosThe Code

#2 Remember your Batch ScenariosThe Criminal Test

#2 Remember your Batch ScenariosThe Correct Test

#3 Test Roles with RunAs

• Test execution defaults to running as System Admin

• Using RunAs allows you to test your sharing rules and

record access rights

#3 Test Roles with RunAs

#3 Test Roles with RunAsThe Correct Test

#4 Test Every Branch of Logic

• Making sure test cases traverse every possible logical

route through your code

• Crucial pieces of logic can be hidden in IF/ELSE blocks

#4 Test Every Branch of LogicThe Code

#4 Test Every Branch of LogicThe Criminal Test

#4 Test Every Branch of LogicThe Coverage

#4 Test Every Branch of LogicThe Correct Test

#5 The 75% Squad

• Those developers who just strive to get to the 75% mark

• Normally guilty of most of the other crimes

• There’s no future for their code and their work

#5 The 75% SquadThe Code

#5 The 75% SquadThe Criminal Test

#5 The 75% SquadThe Coverage

The Wrap Up

• Always have test Assertions

• Batch test your Triggers

• RunAs different Users in your tests

• Cover every branch of your logical flow

• Don’t just aim for 75%

Resources

• These Slides

http://www.slideshare.net/SimonLawrence4

• Developer Resources

https://developer.salesforce.com

https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests

• Salesforce Stack Exchange

http://salesforce.stackexchange.com/

Thank You!

Christopher Alun

Lewis

@ChrisAlunLewis

Simon Lawrence

@srlawr