2. Agenda
Quick Recap on Mocking
01
Static Vs Dynamic Mocks
03
Challenges and Best Practices
06
Q & A
07
Development Vs API Mocks
02
Advanced Mocking Techniques
05
Mocks Vs Intercepts
04
3. WHAT IS A MOCK?
WHY WE NEED IT? ADVANTAGES
Quick Recap
CHALLENGES
•Isolation of Components
•Support in Testing
•Parallel Development
•Prototyping concepts
•Reduce Dependencies
•Faster Feedback
•Cost Efficient
•Data consistency
•Maintainability
•Realism
4. Development Vs API Mocks
Development Mocks:
⚬ Used during the development phase.
⚬ Simulate behavior of components or
modules or databases.
API Mocks:
⚬ Used for testing APIs or services.
⚬ Mimic the responses of real APIs.
5. Static Vs Dynamic Mocking
Static Mocking
•No logic
•Same response every time
•Pay load generated from schemas/examples
•Flaky in nature
•Not realistic
Dynamic Mocking
•Based on input
•Reuse input in output
•Scripting can be used
•Data driven
•Simulate state
•Simulate errors
•More realistic
6. Mocks Vs Intercepts
Mocks:
■ Simulated responses of real APIs.
■ No dependency on a live system.
■ May not perfectly replicate the real API
but provides controlled responses.
Tools: WireMock, Postman or custom scripts
can be used for API mocking.
Use cases: Ideal for scenarios where the
actual API is unavailable.
Intercepts:
■ Modifying actual API requests and responses
during runtime.
■ Requires a live API to intercept and modify
requests and responses.
■ Directly interacts with the real API, ensuring
realism in terms of data and behavior.
Tools: Charles Proxy, Burp Suite or custom code can
be used for API intercepts.
Use cases: Useful for debugging, modifying responses
for specific test scenarios, and understanding API
interactions during development.
7. Advanced Mocking Techniques
•Dynamic Mocking
•Conditional Mocking
•Fake data generation for mocks
•Stateful Mocking
•Error Simulation
•Callback
•Proxy
8.
9. Best Practices
•Align Mocks with API Documentation
•Use dynamic mocking techniques
•Consider versioning in the mocks
•Update the mocks regularly
•Document guidelines for creating/maintaining the mocks.
•Use tools/scripting/GenAI to generate the mocks.