SlideShare a Scribd company logo
Test Driven Development
on Force.com projects
Myths and Truths
March 10, 2016
Aldo Fernandez
Technical Architect
@aldoforce
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve
risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com,
inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of
historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any
statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or
upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our
service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in
our Web hosting, breach of our security measures, risks associated with possible mergers and acquisitions, the immature market in which we operate,
our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and
successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers.
Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the
most recent fiscal quarter ended July 31, 2011. This document and others are available on the SEC Filings section of the Investor Information section of
our Web site.
Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered
on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available.
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Agenda
▪ What is TDD?
▪ TDD Process
▪ An Apex TDD Example
▪ Benefits
▪ Challenges
What is TDD? (I)
▪ …but first, what IS NOT TDD:
▪ TDD is not BDD (Behavior Driven Development)
▪ BDD: specs define tests, and then test defines code implementation
▪ BDD in Apex: Specs -> Test class -> class
▪ Cucumber (cucumber.io) based projects (Pickle, Pepino, …) which runs
acceptance tests defined in Gherkin
▪ …so, what IS TDD?
What is TDD? (II)
▪ It refers to a style of programming where three activities are tightly
interwoven:
▪ Coding
▪ Testing (in the form of unit tests)
▪ Design (in the form of refactoring)
What is TDD? (III)
“TDD is a software development
approach where tests are written
before the functional code”
“TDD is a technique of using
automated unit tests to drive the
design of software and force
decoupling of dependencies”
The TDD process
1. Write a test
2. Run all tests (the new should fail)
3. Write some code
4. Run tests
5. If tests passes, refactor
6. Repeat step 1
Unit Tests vs Integration Tests
▪ Unit Test
▪ Verify that a relatively small piece of
code is doing what is intended to do
▪ Narrow in scope
▪ Easy to write and execute
▪ Test useful for the developer
▪ No dependencies on external
components
▪ External components are mocked or
stubbed out
▪ Test internal consistency
▪ Integration Tests
▪ Verify that different pieces of the
system works correctly together.
▪ Covers whole business
requirements/features
▪ Require more resources to complete
▪ Test useful for business
▪ Dependencies are required because
the holistic approch.
▪ Test consistency between
components
An Apex TDD example (I)
▪ Aldo’s Algebra (don’t google… it’s just a trivial example!)
▪ Given 2 integer numbers (a, b) the sum operation will be a + b
▪ if one of the numbers is null, treat it as zero
▪ examples
▪ AA.sum(2, 3) = 5
▪ AA.sum(2, null) = 2
▪ AA.sum(null, null) = 0
An Apex TDD example (II)
An Apex TDD example (III)
An Apex TDD example (IV)
Repeat the process until
complete the spec
…but what if I have dependencies
on other classes/components?
An Apex TDD example (V)
AlgebraController
<<class>>
AlgebraServices
<<class>>
Algebra
<<page>>
An Apex TDD example (VI)
Dependency Injection
An Apex TDD example (VII)
An Apex TDD example (VIII)
Benefits
▪ Forces good architecture design
▪ Reduce time of bug hunting
▪ Creates a detailed specification
▪ Write shorter and less complex code
▪ Fewer system.debug() statements ;-)
▪ Instant feedback on broken code
▪ Code coverage on steroids (goodbye less than 75%)
▪ Enforce KISS and YAGNI
▪ Tests run faster
▪ Mocking around SOQL and DML to avoid declarative changes failures o/
Challenges
▪ Learning curve
▪ Cost of TDD vs Project Budget
▪ ROI with TDD
▪ Advanced concepts
▪ Dependency Injection
▪ Mocking
▪ Cultural issues
▪ Handling business requirements changes
Resources + Kudos
▪ Test Driven Development Method in Software Development Process. Denis Duka, Lovre
Hribar 2010
▪ Test Driven Development in Apex by Chris Aldridge (@caldrig3)
▪ Cucumber (cucumber.io)
▪ Pickle, a lightweight Cucumber implementation for Salesforce.com, github.com/lpoulain/pickle
▪ Pepino, BDD framework for Apex. github.com/pbattisson/pepino
▪ Unit Testing, Apex Enterprise Patterns and ApexMock, Andrew Fawcett (@andyinthecloud)
▪ Writing true unit tests using dependency injection mocking apex, Alex Tennant (@adtennant)
▪ ApexMocks: How Does It Work? Jesse Altman (@jessealtman)
▪ Inversion of Control Containers and the Dependency Injection Pattern. Martin Fowler, 2004
▪ Demo Code repo: https://github.com/aldoforce/uysdug_tdd_demo
Thank You!
Test Driven Development on
Force.com projects
Myths and Truths
Uruguay Salesforce Developer Group
March 10, 2016
#UYSDUG
Aldo Fernandez
Technical Architect
@aldoforce
#uysdug
#tdd
#dependencyInjection
#apex
#testing

More Related Content

PDF
Behaviour Driven Development (BDD) With Apex on Force.com
PPTX
Agile Testing and Test Automation
PDF
Software Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect States
PPT
Difference between functional testing and non functional testing
PPTX
Preparing for SRE Interviews
PDF
Test cases
KEY
Testing with Jenkins, Selenium and Continuous Deployment
PPTX
Unit tests & TDD
Behaviour Driven Development (BDD) With Apex on Force.com
Agile Testing and Test Automation
Software Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect States
Difference between functional testing and non functional testing
Preparing for SRE Interviews
Test cases
Testing with Jenkins, Selenium and Continuous Deployment
Unit tests & TDD

What's hot (20)

PDF
An Introduction to Test Driven Development
PPT
Selenium ppt
PPTX
Branching and Merging Practices
PPT
Load Testing Strategy 101
DOC
Manual testing interview question by INFOTECH
PDF
Bdd Introduction
PPTX
Bug life cycle
PDF
PPTX
Introduction to Selenium Web Driver
PPT
Agile QA presentation
PPTX
Jenkins CI presentation
PPT
Basic software-testing-concepts
PPT
Performance and load testing
ODP
Refactoring Techniques
PDF
Fundamentals Performance Testing
PPTX
Performance Testing from Scratch + JMeter intro
PPT
Capturing Measurable Non Functional Requirements
PPTX
Git branching strategies
PPT
Bug Reporting
PDF
Code Refactoring
An Introduction to Test Driven Development
Selenium ppt
Branching and Merging Practices
Load Testing Strategy 101
Manual testing interview question by INFOTECH
Bdd Introduction
Bug life cycle
Introduction to Selenium Web Driver
Agile QA presentation
Jenkins CI presentation
Basic software-testing-concepts
Performance and load testing
Refactoring Techniques
Fundamentals Performance Testing
Performance Testing from Scratch + JMeter intro
Capturing Measurable Non Functional Requirements
Git branching strategies
Bug Reporting
Code Refactoring
Ad

Similar to Test Driven Development (TDD) on Force.com projects (20)

PDF
Manage Development in Your Org with Salesforce Governance Framework
PDF
Best Practices for Team Development in a Single Org
PPT
Designing custom REST and SOAP interfaces on Force.com
PDF
Continuous Integration - Software development lifecycle for Force.com projects
PDF
API Design for Your Packaged App
PPTX
Building Command-line Tools with the Tooling API
PDF
Development Best Practices
PDF
Building Complex Traversing & Branching Apps Using Visual Workflows and Apex
PDF
Designing Custom REST and SOAP Interfaces on Force.com
PDF
API Design for Your Packaged App
PPTX
Force.com Friday : Intro to Apex
PDF
Introduction to Apex Triggers
PPTX
Intro to Salesforce Lightning for Admins
PDF
TDX19 - Accelerate DevOps with GitLab and Salesforce
PPTX
Bridging the Gap between Clicks & Code
PPTX
Elevate Madrid Essentials - Advance Track
PPTX
Lightning Developer Experience, Eclipse IDE Evolved
PPTX
Get Started with Salesforce DX!
PDF
Shorten Your Development Time with an Extensible Design for Apex
PPTX
Enterprise-grade UI with open source Lightning Web Components
Manage Development in Your Org with Salesforce Governance Framework
Best Practices for Team Development in a Single Org
Designing custom REST and SOAP interfaces on Force.com
Continuous Integration - Software development lifecycle for Force.com projects
API Design for Your Packaged App
Building Command-line Tools with the Tooling API
Development Best Practices
Building Complex Traversing & Branching Apps Using Visual Workflows and Apex
Designing Custom REST and SOAP Interfaces on Force.com
API Design for Your Packaged App
Force.com Friday : Intro to Apex
Introduction to Apex Triggers
Intro to Salesforce Lightning for Admins
TDX19 - Accelerate DevOps with GitLab and Salesforce
Bridging the Gap between Clicks & Code
Elevate Madrid Essentials - Advance Track
Lightning Developer Experience, Eclipse IDE Evolved
Get Started with Salesforce DX!
Shorten Your Development Time with an Extensible Design for Apex
Enterprise-grade UI with open source Lightning Web Components
Ad

More from Aldo Fernandez (8)

PDF
November meetup - Hello Winter'16
PDF
06 august meetup - enterprise integration architecture
PDF
Procesando Salesforce Outbound Messages con PHP en Heroku
PDF
04 june meetup - An overview of OAuth2 on Force.com projects
PDF
Processing outbound messages with Node.js
PDF
Salesforce1 dev week UYSDUG 2014 - the force canvas spark
PDF
Salesforce1 lightning dev week UYSDUG 2015 - Lightning Connect
PDF
Salesforce mobile dev weel UYSDUG 2013 - Enabling restful services for mobile...
November meetup - Hello Winter'16
06 august meetup - enterprise integration architecture
Procesando Salesforce Outbound Messages con PHP en Heroku
04 june meetup - An overview of OAuth2 on Force.com projects
Processing outbound messages with Node.js
Salesforce1 dev week UYSDUG 2014 - the force canvas spark
Salesforce1 lightning dev week UYSDUG 2015 - Lightning Connect
Salesforce mobile dev weel UYSDUG 2013 - Enabling restful services for mobile...

Recently uploaded (20)

PPT
introduction to datamining and warehousing
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
web development for engineering and engineering
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Current and future trends in Computer Vision.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
introduction to datamining and warehousing
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
OOP with Java - Java Introduction (Basics)
CYBER-CRIMES AND SECURITY A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
additive manufacturing of ss316l using mig welding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Model Code of Practice - Construction Work - 21102022 .pdf
bas. eng. economics group 4 presentation 1.pptx
Sustainable Sites - Green Building Construction
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
web development for engineering and engineering
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Current and future trends in Computer Vision.pptx
CH1 Production IntroductoryConcepts.pptx
573137875-Attendance-Management-System-original
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...

Test Driven Development (TDD) on Force.com projects

  • 1. Test Driven Development on Force.com projects Myths and Truths March 10, 2016
  • 3. Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal quarter ended July 31, 2011. This document and others are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 4. Agenda ▪ What is TDD? ▪ TDD Process ▪ An Apex TDD Example ▪ Benefits ▪ Challenges
  • 5. What is TDD? (I) ▪ …but first, what IS NOT TDD: ▪ TDD is not BDD (Behavior Driven Development) ▪ BDD: specs define tests, and then test defines code implementation ▪ BDD in Apex: Specs -> Test class -> class ▪ Cucumber (cucumber.io) based projects (Pickle, Pepino, …) which runs acceptance tests defined in Gherkin ▪ …so, what IS TDD?
  • 6. What is TDD? (II) ▪ It refers to a style of programming where three activities are tightly interwoven: ▪ Coding ▪ Testing (in the form of unit tests) ▪ Design (in the form of refactoring)
  • 7. What is TDD? (III) “TDD is a software development approach where tests are written before the functional code” “TDD is a technique of using automated unit tests to drive the design of software and force decoupling of dependencies”
  • 8. The TDD process 1. Write a test 2. Run all tests (the new should fail) 3. Write some code 4. Run tests 5. If tests passes, refactor 6. Repeat step 1
  • 9. Unit Tests vs Integration Tests ▪ Unit Test ▪ Verify that a relatively small piece of code is doing what is intended to do ▪ Narrow in scope ▪ Easy to write and execute ▪ Test useful for the developer ▪ No dependencies on external components ▪ External components are mocked or stubbed out ▪ Test internal consistency ▪ Integration Tests ▪ Verify that different pieces of the system works correctly together. ▪ Covers whole business requirements/features ▪ Require more resources to complete ▪ Test useful for business ▪ Dependencies are required because the holistic approch. ▪ Test consistency between components
  • 10. An Apex TDD example (I) ▪ Aldo’s Algebra (don’t google… it’s just a trivial example!) ▪ Given 2 integer numbers (a, b) the sum operation will be a + b ▪ if one of the numbers is null, treat it as zero ▪ examples ▪ AA.sum(2, 3) = 5 ▪ AA.sum(2, null) = 2 ▪ AA.sum(null, null) = 0
  • 11. An Apex TDD example (II)
  • 12. An Apex TDD example (III)
  • 13. An Apex TDD example (IV) Repeat the process until complete the spec
  • 14. …but what if I have dependencies on other classes/components?
  • 15. An Apex TDD example (V) AlgebraController <<class>> AlgebraServices <<class>> Algebra <<page>>
  • 16. An Apex TDD example (VI)
  • 18. An Apex TDD example (VII)
  • 19. An Apex TDD example (VIII)
  • 20. Benefits ▪ Forces good architecture design ▪ Reduce time of bug hunting ▪ Creates a detailed specification ▪ Write shorter and less complex code ▪ Fewer system.debug() statements ;-) ▪ Instant feedback on broken code ▪ Code coverage on steroids (goodbye less than 75%) ▪ Enforce KISS and YAGNI ▪ Tests run faster ▪ Mocking around SOQL and DML to avoid declarative changes failures o/
  • 21. Challenges ▪ Learning curve ▪ Cost of TDD vs Project Budget ▪ ROI with TDD ▪ Advanced concepts ▪ Dependency Injection ▪ Mocking ▪ Cultural issues ▪ Handling business requirements changes
  • 22. Resources + Kudos ▪ Test Driven Development Method in Software Development Process. Denis Duka, Lovre Hribar 2010 ▪ Test Driven Development in Apex by Chris Aldridge (@caldrig3) ▪ Cucumber (cucumber.io) ▪ Pickle, a lightweight Cucumber implementation for Salesforce.com, github.com/lpoulain/pickle ▪ Pepino, BDD framework for Apex. github.com/pbattisson/pepino ▪ Unit Testing, Apex Enterprise Patterns and ApexMock, Andrew Fawcett (@andyinthecloud) ▪ Writing true unit tests using dependency injection mocking apex, Alex Tennant (@adtennant) ▪ ApexMocks: How Does It Work? Jesse Altman (@jessealtman) ▪ Inversion of Control Containers and the Dependency Injection Pattern. Martin Fowler, 2004 ▪ Demo Code repo: https://github.com/aldoforce/uysdug_tdd_demo
  • 23. Thank You! Test Driven Development on Force.com projects Myths and Truths Uruguay Salesforce Developer Group March 10, 2016 #UYSDUG Aldo Fernandez Technical Architect @aldoforce #uysdug #tdd #dependencyInjection #apex #testing