Testing From The Trenches - Salesforce1 World Tour 2014

27
Testing From The Trenches May 22nd, 2014

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.

Transcript of Testing From The Trenches - Salesforce1 World Tour 2014

Page 1: Testing From The Trenches - Salesforce1 World Tour 2014

Testing From The TrenchesMay 22nd, 2014

Page 2: Testing From The Trenches - Salesforce1 World Tour 2014

Christopher Alun Lewis

Advanced Developer

Force.com MVP

A Developers Perspective

Simon Lawrence

Certified Developer

Force.com MVP

http://www.slideshare.net/SimonLawrence4

Page 3: Testing From The Trenches - Salesforce1 World Tour 2014

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

Page 4: Testing From The Trenches - Salesforce1 World Tour 2014

Testing on Salesforce

Our 5 Top Tips for Testing

Page 5: Testing From The Trenches - Salesforce1 World Tour 2014

#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

Page 6: Testing From The Trenches - Salesforce1 World Tour 2014

#1 Always Include AssertionsThe Code

Page 7: Testing From The Trenches - Salesforce1 World Tour 2014

#1 Always Include AssertionsThe Criminal Test

Page 8: Testing From The Trenches - Salesforce1 World Tour 2014

#1 Always Include AssertionsThe Correct Test

Page 9: Testing From The Trenches - Salesforce1 World Tour 2014

#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

Page 10: Testing From The Trenches - Salesforce1 World Tour 2014

#2 Remember your Batch ScenariosThe Code

Page 11: Testing From The Trenches - Salesforce1 World Tour 2014

#2 Remember your Batch ScenariosThe Criminal Test

Page 12: Testing From The Trenches - Salesforce1 World Tour 2014

#2 Remember your Batch ScenariosThe Correct Test

Page 13: Testing From The Trenches - Salesforce1 World Tour 2014

#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

Page 14: Testing From The Trenches - Salesforce1 World Tour 2014

#3 Test Roles with RunAs

Page 15: Testing From The Trenches - Salesforce1 World Tour 2014

#3 Test Roles with RunAsThe Correct Test

Page 16: Testing From The Trenches - Salesforce1 World Tour 2014

#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

Page 17: Testing From The Trenches - Salesforce1 World Tour 2014

#4 Test Every Branch of LogicThe Code

Page 18: Testing From The Trenches - Salesforce1 World Tour 2014

#4 Test Every Branch of LogicThe Criminal Test

Page 19: Testing From The Trenches - Salesforce1 World Tour 2014

#4 Test Every Branch of LogicThe Coverage

Page 20: Testing From The Trenches - Salesforce1 World Tour 2014

#4 Test Every Branch of LogicThe Correct Test

Page 21: Testing From The Trenches - Salesforce1 World Tour 2014

#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

Page 22: Testing From The Trenches - Salesforce1 World Tour 2014

#5 The 75% SquadThe Code

Page 23: Testing From The Trenches - Salesforce1 World Tour 2014

#5 The 75% SquadThe Criminal Test

Page 24: Testing From The Trenches - Salesforce1 World Tour 2014

#5 The 75% SquadThe Coverage

Page 25: Testing From The Trenches - Salesforce1 World Tour 2014

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%

Page 26: Testing From The Trenches - Salesforce1 World Tour 2014

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/

Page 27: Testing From The Trenches - Salesforce1 World Tour 2014

Thank You!

Christopher Alun

Lewis

@ChrisAlunLewis

Simon Lawrence

@srlawr