SlideShare a Scribd company logo
1 of 27
Enhanced Web Service Testing
Kirk Steffke
AppExchange Practice Lead
kirk@crmscience.com
@kirkevonphilly
A Better Mock Structure
• Test Coverage Overview
• Review of Native Testing Methods
• WebServiceMock and HttpCalloutMock
Interfaces
• StaticResourceCalloutMock
• MultiStaticResourceCalloutMock
• Sample Scenarios
• Better Mock Structure
• Setup
• Review
Agenda
During this session
Test Coverage Overview
• Who: Developers
• What: Code written… about code
• When: Production Org bound code
• Where: Sandboxes and developer orgs
• Why: Safety first
Apex Test Coverage
Who, What, When, Where, and Why
Apex Test Coverage
Who, What, When, Where, and Why
Works!
Doesn’t
Work!
Should Good work!
!
Shouldn’t ! (silence)
Apex Test Coverage
A Bit More of “How”
Grandma’s Famous Recipe
1. Write code to do
something
2. Create test class
3. Mark with @isTest
4. Create test method
5. Create test data
6. Invoke code being tested
7. Assert (+ or -)
Native Testing Strategies
The Tools that are Already in your Toolbox
• Exist/defined in a separate
class
• Returns single callout
response
• WebServiceMock for WSDL
based SOAP callouts
• HttpCalloutMock for testing
Http callouts
• Defined by content of text file
in Static Resource
• Returns response for a single
endpoint
• Similar to
StaticResourceCalloutMock
• Static Resource contains
response for multiple
endpoints
WebServiceMock and
HttpCalloutMock Interfaces
StaticResourceCalloutMock MultiStaticResourceCalloutMock
Documentation: bit.ly/df15mock3Documentation: bit.ly/df15mock1 Documentation: bit.ly/df15mock2
Options for Testing HTTP Callouts
Out-of-the-box Tools
• Class with single method
• Method makes a callout
• Testing with:
• HttpCalloutMock Interface
• StaticResourceCalloutMock
Upcoming Examples
Examples 1 and 2: Single Callout
Class
Callout Method
External API Endpoint
Request
Response
• Class with three methods
• Two methods make different callouts
• One method calls both callout methods
• Testing with:
• MultiStaticResourceCalloutMock
Upcoming Examples
Example 3: Multiple Callouts
External API Endpoint 2Request
Response
Class
External API Endpoint 1
Request
Response
Both Callouts
Callout Method 2
Callout Method 1
Code Demos
Examples 1, 2, and 3
Complex Scenario
A hypothetical, but real-world model to help you digest
• Batch job
• Import of Contacts from remote system
• Remote system has an API
• Two endpoints
• /api/ContactCount
• /api/Contacts
Remote Import via Batch
Overview
• /api/ContactCount
• Returns # of Contact records to be imported
• Result can change during span of batch execution
• /api/Contacts
• Returns x number of contacts
• Paginated
• Page=1 – returns 1st 200 records
• Page=2 – returns 2nd 200 records
• …and so on
Remote Import via Batch
Meet the Endpoints
1. Batch is called
2. Start() method
3. Each execute() iteration performs 2 callouts
4. 1st checks total # of records available
5. 2nd imports records
6. End of execute determines if more
records?
7. Execute may run for many iterations
8. If no more records or limits, finish()
9. Restart cycle
10. End
Remote Import via Batch
Batch Flow
• Class with three methods
• Two methods make different callouts
• One method calls both callout methods
• Simulate batch w/ a loop
Upcoming Examples
Example 4: Multiple Everything
Contact DataRequest
Response
Class
Callout Method 1
Contact Count
Request
ResponseCallout Method 2
x10
Limitations
Working with Our Tools
• HttpCalloutMock Interface and StaticResourceMock
• Can only handle one endpoint
• Single response
• Single setup prior to invoking actual callouts
• MultiStaticResourceCalloutMock
• Handle multiple endpoints
• Single response for each
• Single setup prior to invoking actual callouts
Problems
Continued…
• Challenge
• Use one or more standard tool
• Extend the usage
• Create queue of expected responses per endpoint
• Consider re-usability
Response Generator
The Playlist Structure
Method
GET/POST/etc
Endpoint
/api/endpoint
Responses
[0] response 1
[1] response 2
[x] response x
• Like music at a party
• Some want to rock
• Some want to dance
• Sometimes you want to hear the same song again
Response Generator
The “Count” Playlist
Method
GET
Endpoint
Contact Count
Responses
[0] 10 Contacts
[1] 12 Contacts
[x] 12 Contacts
Response Generator
The “Data” Playlist
Method
GET
Endpoint
Contact Data
Responses
[0] Data 0-199
[1] Data 200-399
[9] Data x
Code Demo
Example 4
Testing the Solution
TestCalloutClass
1. Count or Contact callout
2. # of loop iteration
3. Count data 10, 12, 12, …
1. Use 1st, discard
2. Use 2nd, don’t discard
4. Contact data increments
1. Provided per page response
Resources
Blog.crmscience.com
• Blog Post: http://bit.ly/df15_kirk_blog
• Unmanaged Package with all examples: http://bit.ly/df15_kirk_pack
• Link to deck: http://bit.ly/df15_kirk_deck
Share Your Feedback, and Win a GoPro!
3
Earn a GoPro prize entry for
each completed survey
Tap the bell to take a survey2Enroll in a session1
Questions
Find One of Us in a Lab Coat
Thank you

More Related Content

What's hot

PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0William Munn
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeIan Robertson
 
Applying TDD to Legacy Code
Applying TDD to Legacy CodeApplying TDD to Legacy Code
Applying TDD to Legacy CodeAlexander Goida
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateLB Denker
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0William Munn
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Strongersnyff
 
Sonar rules in action with walkmod
Sonar rules in action with walkmodSonar rules in action with walkmod
Sonar rules in action with walkmodRaquel Pau
 
BSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwertyBSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwertyJerome Smith
 
Cassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsCassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsChristopher Batey
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The ApproachHaci Murat Yaman
 
Integrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into GalaxyIntegrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into Galaxypjacock
 
Soap UI - Lesson45
Soap UI - Lesson45Soap UI - Lesson45
Soap UI - Lesson45Qualitest
 

What's hot (20)

Android dev 3
Android dev 3Android dev 3
Android dev 3
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
 
Applying TDD to Legacy Code
Applying TDD to Legacy CodeApplying TDD to Legacy Code
Applying TDD to Legacy Code
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Stronger
 
Sonar rules in action with walkmod
Sonar rules in action with walkmodSonar rules in action with walkmod
Sonar rules in action with walkmod
 
BSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwertyBSides MCR 2016: From CSV to CMD to qwerty
BSides MCR 2016: From CSV to CMD to qwerty
 
Cassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsCassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra Applications
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Integrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into GalaxyIntegrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into Galaxy
 
Soap UI - Lesson45
Soap UI - Lesson45Soap UI - Lesson45
Soap UI - Lesson45
 
Celery
CeleryCelery
Celery
 

Similar to Enhanced Web Service Testing: A Better Mock Structure

Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticLB Denker
 
Seven deadly sins of ElasticSearch Benchmarking
Seven deadly sins of ElasticSearch BenchmarkingSeven deadly sins of ElasticSearch Benchmarking
Seven deadly sins of ElasticSearch BenchmarkingFan Robbin
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Andrew Krug
 
Run around Chrome Inspector
Run around Chrome Inspector Run around Chrome Inspector
Run around Chrome Inspector Tiang Cheng
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engineIlya Puchka
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesLeo Loobeek
 
Awesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave HaeffnerAwesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave HaeffnerSauce Labs
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopchartjes
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaYardena Meymann
 
Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)Brian Brazil
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Dave Haeffner
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Web hacking series part 3
Web hacking series part 3Web hacking series part 3
Web hacking series part 3Aditya Kamat
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to useUma Ghotikar
 
Azure Cloud Patterns
Azure Cloud PatternsAzure Cloud Patterns
Azure Cloud PatternsTamir Dresher
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 

Similar to Enhanced Web Service Testing: A Better Mock Structure (20)

Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Seven deadly sins of ElasticSearch Benchmarking
Seven deadly sins of ElasticSearch BenchmarkingSeven deadly sins of ElasticSearch Benchmarking
Seven deadly sins of ElasticSearch Benchmarking
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
 
Run around Chrome Inspector
Run around Chrome Inspector Run around Chrome Inspector
Run around Chrome Inspector
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
Awesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave HaeffnerAwesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave Haeffner
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshop
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
 
Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Web hacking series part 3
Web hacking series part 3Web hacking series part 3
Web hacking series part 3
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
 
Azure Cloud Patterns
Azure Cloud PatternsAzure Cloud Patterns
Azure Cloud Patterns
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 

Recently uploaded

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Enhanced Web Service Testing: A Better Mock Structure

  • 1. Enhanced Web Service Testing Kirk Steffke AppExchange Practice Lead kirk@crmscience.com @kirkevonphilly A Better Mock Structure
  • 2. • Test Coverage Overview • Review of Native Testing Methods • WebServiceMock and HttpCalloutMock Interfaces • StaticResourceCalloutMock • MultiStaticResourceCalloutMock • Sample Scenarios • Better Mock Structure • Setup • Review Agenda During this session
  • 4. • Who: Developers • What: Code written… about code • When: Production Org bound code • Where: Sandboxes and developer orgs • Why: Safety first Apex Test Coverage Who, What, When, Where, and Why
  • 5. Apex Test Coverage Who, What, When, Where, and Why Works! Doesn’t Work! Should Good work! ! Shouldn’t ! (silence)
  • 6. Apex Test Coverage A Bit More of “How” Grandma’s Famous Recipe 1. Write code to do something 2. Create test class 3. Mark with @isTest 4. Create test method 5. Create test data 6. Invoke code being tested 7. Assert (+ or -)
  • 7. Native Testing Strategies The Tools that are Already in your Toolbox
  • 8. • Exist/defined in a separate class • Returns single callout response • WebServiceMock for WSDL based SOAP callouts • HttpCalloutMock for testing Http callouts • Defined by content of text file in Static Resource • Returns response for a single endpoint • Similar to StaticResourceCalloutMock • Static Resource contains response for multiple endpoints WebServiceMock and HttpCalloutMock Interfaces StaticResourceCalloutMock MultiStaticResourceCalloutMock Documentation: bit.ly/df15mock3Documentation: bit.ly/df15mock1 Documentation: bit.ly/df15mock2 Options for Testing HTTP Callouts Out-of-the-box Tools
  • 9. • Class with single method • Method makes a callout • Testing with: • HttpCalloutMock Interface • StaticResourceCalloutMock Upcoming Examples Examples 1 and 2: Single Callout Class Callout Method External API Endpoint Request Response
  • 10. • Class with three methods • Two methods make different callouts • One method calls both callout methods • Testing with: • MultiStaticResourceCalloutMock Upcoming Examples Example 3: Multiple Callouts External API Endpoint 2Request Response Class External API Endpoint 1 Request Response Both Callouts Callout Method 2 Callout Method 1
  • 12. Complex Scenario A hypothetical, but real-world model to help you digest
  • 13. • Batch job • Import of Contacts from remote system • Remote system has an API • Two endpoints • /api/ContactCount • /api/Contacts Remote Import via Batch Overview
  • 14. • /api/ContactCount • Returns # of Contact records to be imported • Result can change during span of batch execution • /api/Contacts • Returns x number of contacts • Paginated • Page=1 – returns 1st 200 records • Page=2 – returns 2nd 200 records • …and so on Remote Import via Batch Meet the Endpoints
  • 15. 1. Batch is called 2. Start() method 3. Each execute() iteration performs 2 callouts 4. 1st checks total # of records available 5. 2nd imports records 6. End of execute determines if more records? 7. Execute may run for many iterations 8. If no more records or limits, finish() 9. Restart cycle 10. End Remote Import via Batch Batch Flow
  • 16. • Class with three methods • Two methods make different callouts • One method calls both callout methods • Simulate batch w/ a loop Upcoming Examples Example 4: Multiple Everything Contact DataRequest Response Class Callout Method 1 Contact Count Request ResponseCallout Method 2 x10
  • 17. Limitations Working with Our Tools • HttpCalloutMock Interface and StaticResourceMock • Can only handle one endpoint • Single response • Single setup prior to invoking actual callouts • MultiStaticResourceCalloutMock • Handle multiple endpoints • Single response for each • Single setup prior to invoking actual callouts
  • 18. Problems Continued… • Challenge • Use one or more standard tool • Extend the usage • Create queue of expected responses per endpoint • Consider re-usability
  • 19. Response Generator The Playlist Structure Method GET/POST/etc Endpoint /api/endpoint Responses [0] response 1 [1] response 2 [x] response x • Like music at a party • Some want to rock • Some want to dance • Sometimes you want to hear the same song again
  • 20. Response Generator The “Count” Playlist Method GET Endpoint Contact Count Responses [0] 10 Contacts [1] 12 Contacts [x] 12 Contacts
  • 21. Response Generator The “Data” Playlist Method GET Endpoint Contact Data Responses [0] Data 0-199 [1] Data 200-399 [9] Data x
  • 23. Testing the Solution TestCalloutClass 1. Count or Contact callout 2. # of loop iteration 3. Count data 10, 12, 12, … 1. Use 1st, discard 2. Use 2nd, don’t discard 4. Contact data increments 1. Provided per page response
  • 24. Resources Blog.crmscience.com • Blog Post: http://bit.ly/df15_kirk_blog • Unmanaged Package with all examples: http://bit.ly/df15_kirk_pack • Link to deck: http://bit.ly/df15_kirk_deck
  • 25. Share Your Feedback, and Win a GoPro! 3 Earn a GoPro prize entry for each completed survey Tap the bell to take a survey2Enroll in a session1
  • 26. Questions Find One of Us in a Lab Coat