SlideShare a Scribd company logo
Stateful mock servers to the
rescue on REST ecosystems
netponto - 2018-04-07
Nuno Caneco
Nuno Caneco
/@nuno.caneco
/nunocaneco
nuno.caneco@gmail.com
Engineering Manager / Cluster Lead
@nunocaneco
Raise your hands
Stateful mock servers to the rescue on REST ecosystems
The Monolith
A monolith is a geological feature consisting of a single massive stone or rock, such as some
mountains, or a single large piece of rock placed as, or within, a monument or building.
https://en.wikipedia.org/wiki/Monolith
A software system is called "monolithic" if it has a monolithic architecture, in which functionally
distinguishable aspects (for example data input and output, data processing, error handling, and the
user interface) are all interwoven, rather than containing architecturally separate components.
https://en.wikipedia.org/wiki/Monolithic_system
Monolithic architecture
Storefront
UI
Backoffice
UI
Catalog Service
User Service
Order Service
(...)
Database
Mobile
Web API
Microservices architecture
Storefront
UI
Backoffice
UI
User
Service
Mobile
Web API
Catalog
Service
Order
Service
REST
REST has become the default technology to support Microservices Architecture
● It's HTTP(S)
● Use HTTP Verbs for actions: GET, PUT, POST, DELETE, PATCH, ...
● Use HTTP Status Codes to provide meaningful and normalized responses to
clients
● Easily extensible using HTTP Headers
● Support multiple authentication mechanisms
● JSON is more simple and less verbose than XML
The growth of a
Microservice
Application
Ecosystem
User interfacePublic API
Backend Services
Publish / Subscribe
Databases
BLOB Storage
3rd party systems
Component Dependency
System Complexity ~= Business Complexity
Loose coupling ; High dependency
Dependency
level = 0
Dependency
level = 10
Dependency
level = 7
Teams & Components
Combine dependency level with
● Development environment
○ Setup
○ Maintain
● Keep services up to date
● Keep database schema and data
● Test
○ Time it takes to finish tests
○ Dependency from data
● CI/CD
○ Keep a stable environment for end-to-end tests
● Contract stability
● Communication between maintainers
Fakes to the
rescue
Terminology
Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
Fake objects actually have working implementations, but usually take some shortcut which makes them not
suitable for production (an in memory database is a good example).
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside
what's programmed in for the test.
Spies are stubs that also record some information based on how they were called. One form of this might be an
email service that records how many messages it was sent.
Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to
receive.
https://martinfowler.com/articles/mocksArentStubs.html
Mock your dependencies
Dependencies with real implementations are
replaced by mocked implementations that
provide similar behavior at the interface level.
Example
Example
Fake Techniques - Client Fake
Client App
XptoAPIClient
Xpto Web API
HTTP
FakeXptoAPI
Client
IXptoApiClient
Quick to implement and simple to use
No new components on the system
Using a Mock framework allows control of
results on automated tests
Doesn't test the HTTP layer
Requires coding to implement statefulness
The Production Code is not stimulated
Potential risk to "Go Live" with the Fake
instead of Real implementation
Fake Techniques - Proxy
Client App
XptoAPIClient
Xpto Web API
HTTP
Quick to implement and simple to use
Saved responses are similar to the real API
No coding necessary (although possible)
Easy to implement with containers
Very flexible: easy to modify responses
Contract changes invalidate previous saved
responses
Requires coding to implement statefulness
Difficult to implement Expectations
mechanism to integrated with automated tests
Store
and
Forward
Proxy
HTTP
Responses
Fake Techniques - Fake Server
Client App
XptoAPIClient
Xpto Web API
HTTP Not so flexible to change responses
Requires coding
Need to implement Expectations to integrate
with automated tests
Code generation accelerates development
Easy support for contract changes:
(just regenerate the code and change implementation)
Easy to create and share containers
Easy to implement statefulness
Fake Xpto Web
API
Production&Integration
Development&Tests
HTTP
Demo I
Proxy
Demo - Proxy
Movie Rating UI
MovieRating
APIClient
Movie Rating Web API
HTTP
Store
and
Forward
Proxy
Responses
Omdb API
Demo II
Fake Server
Demo - Fake Server
Movie Rating UI
MovieRating
APIClient
Movie Rating Web
API
Fake Xpto Web
API
Omdb API
Wrapping up
Integrating with docker
Using docker to launch every 1st dependency allows easy
setup of the project.
$> git clone <repo>
$> docker-compose up deps
Open solution in Visual Studio and hit F5
No expensive setup of databases, messaging systems or other services
Docker images can be versioned alongside with the versions of the API
Can be used to run component tests (not integration tests)
Summary
● Fake the 1st level dependencies to avoid having the entire dependency tree
● Choose your strategy: Client Fake, Proxy, Stateful Fake or any other that suits
● Consider generating as much code as possible
● Potentially high upfront investment - big gains in the long run
● Make it easy for the developers to
○ Run the project
○ Manage the versions of the dependencies they are using
○ Write automated tests
● Make components tests running against Fakes instead
ANY QUESTIONS?
/@nuno.caneco
/nunocaneco
nuno.caneco@gmail.com
THANK YOU
@nunocaneco
Patrocinadores “GOLD”
Twitter: @PTMicrosoft http://www.microsoft.com/portugal
Patrocinadores “GOLD”
Twitter: @FindmoreC http://www.findmore.pt/pt
Patrocinadores “Silver”
Patrocinadores “Bronze”
http://bit.ly/netponto-aval-76
* Para quem não puder preencher durante a reunião,
iremos enviar um email com o link à tarde
Próximas reuniões presenciais
07/04/2018 – Lisboa
23/06/2018 – Lisboa
15/09/2018 – Lisboa
24/11/2018 – Lisboa
Reserva estes dias na agenda! :)

More Related Content

PPTX
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
PPTX
Mvvw patterns
ODP
Microservice Architecture JavaCro 2015
PPTX
Security Model in .NET Framework
PPTX
deliver:Agile 2019 "Testing Microservices: From Development to Production
PPTX
Codeigniter Introduction
PDF
Creating modern java web applications based on struts2 and angularjs
PDF
Introduction to Continuous Integration
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
Mvvw patterns
Microservice Architecture JavaCro 2015
Security Model in .NET Framework
deliver:Agile 2019 "Testing Microservices: From Development to Production
Codeigniter Introduction
Creating modern java web applications based on struts2 and angularjs
Introduction to Continuous Integration

What's hot (19)

PPTX
A simplest way to reconstruct .Net Framework - CRB Tech
PPTX
PHP Symfony MicroServices Migration @MeeticTech
PPTX
PHP Frameworks & Introduction to CodeIgniter
PPTX
Introduction to vb.net
PPT
Implementing application security using the .net framework
PDF
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
PPTX
dotMemory 4 - What's inside?
PPTX
Lap around .net 4
PPTX
Robot framework Gowthami Goli
PPTX
Continuous Integration and development environment approach
PPTX
Practice of AppSec .NET
PDF
Use React tools for better Angular apps
PDF
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
PDF
Testing with Spring 4.x
PDF
Spring Framework Tutorial | VirtualNuggets
PDF
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
PDF
12 factor app - Core Guidelines To Cloud Ready Solutions
PDF
Talking architecture shop - Exploring open source success at scale
PDF
Appium & Robot Framework
A simplest way to reconstruct .Net Framework - CRB Tech
PHP Symfony MicroServices Migration @MeeticTech
PHP Frameworks & Introduction to CodeIgniter
Introduction to vb.net
Implementing application security using the .net framework
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
dotMemory 4 - What's inside?
Lap around .net 4
Robot framework Gowthami Goli
Continuous Integration and development environment approach
Practice of AppSec .NET
Use React tools for better Angular apps
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
Testing with Spring 4.x
Spring Framework Tutorial | VirtualNuggets
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
12 factor app - Core Guidelines To Cloud Ready Solutions
Talking architecture shop - Exploring open source success at scale
Appium & Robot Framework
Ad

Similar to Stateful mock servers to the rescue on REST ecosystems (20)

PPTX
Whats New In 2010 (Msdn & Visual Studio)
PPT
D22 portlet development with open source frameworks
PPT
D22 Portlet Development With Open Source Frameworks
PPT
Widgets - the Wookie project
DOCX
Actively looking for an opportunity to work as a challenging Dot Net Developer
DOCX
Actively looking for an opportunity to work as a challenging Dot Net Developer
PDF
Best practices for creating modular Web applications
PPTX
Techdays 2011 - Things I will remember
PPT
Paremus service fabric
PPTX
Pentesting With Web Services in 2012
PPTX
What's New in InTouch Machine Edition (ITME)
PDF
Advanced web application architecture - Talk
DOCX
Online lg prodect
PPT
soa1.ppt
PDF
Path to continuous delivery
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First
PPT
COMPRO- WEB ALBUM & MOTION ANALYZER
PPTX
DWX2015 - Von Bayern in die Cloud
PPTX
Von Bayern in die Cloud
PDF
The Twelve Factor Apps
Whats New In 2010 (Msdn & Visual Studio)
D22 portlet development with open source frameworks
D22 Portlet Development With Open Source Frameworks
Widgets - the Wookie project
Actively looking for an opportunity to work as a challenging Dot Net Developer
Actively looking for an opportunity to work as a challenging Dot Net Developer
Best practices for creating modular Web applications
Techdays 2011 - Things I will remember
Paremus service fabric
Pentesting With Web Services in 2012
What's New in InTouch Machine Edition (ITME)
Advanced web application architecture - Talk
Online lg prodect
soa1.ppt
Path to continuous delivery
Elements of DDD with ASP.NET MVC & Entity Framework Code First
COMPRO- WEB ALBUM & MOTION ANALYZER
DWX2015 - Von Bayern in die Cloud
Von Bayern in die Cloud
The Twelve Factor Apps
Ad

More from Nuno Caneco (8)

PDF
Building resilient applications
PPTX
Git from the trenches
PDF
Tuga IT 2017 - Redis
PDF
Tuga it 2017 - Event processing with Apache Storm
PDF
Fullstack LX - Improving your application performance
PPTX
Running agile on a non-agile environment
PPTX
Introducing redis
PPTX
Tuga it 2016 improving your application performance
Building resilient applications
Git from the trenches
Tuga IT 2017 - Redis
Tuga it 2017 - Event processing with Apache Storm
Fullstack LX - Improving your application performance
Running agile on a non-agile environment
Introducing redis
Tuga it 2016 improving your application performance

Recently uploaded (20)

PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Internet of Things (IOT) - A guide to understanding
DOCX
573137875-Attendance-Management-System-original
PPT
Project quality management in manufacturing
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Construction Project Organization Group 2.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Welding lecture in detail for understanding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
PPT on Performance Review to get promotions
PPTX
web development for engineering and engineering
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Internet of Things (IOT) - A guide to understanding
573137875-Attendance-Management-System-original
Project quality management in manufacturing
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Lesson 3_Tessellation.pptx finite Mathematics
Model Code of Practice - Construction Work - 21102022 .pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Construction Project Organization Group 2.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Welding lecture in detail for understanding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CH1 Production IntroductoryConcepts.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPT on Performance Review to get promotions
web development for engineering and engineering
bas. eng. economics group 4 presentation 1.pptx
Operating System & Kernel Study Guide-1 - converted.pdf

Stateful mock servers to the rescue on REST ecosystems

  • 1. Stateful mock servers to the rescue on REST ecosystems netponto - 2018-04-07 Nuno Caneco
  • 5. The Monolith A monolith is a geological feature consisting of a single massive stone or rock, such as some mountains, or a single large piece of rock placed as, or within, a monument or building. https://en.wikipedia.org/wiki/Monolith A software system is called "monolithic" if it has a monolithic architecture, in which functionally distinguishable aspects (for example data input and output, data processing, error handling, and the user interface) are all interwoven, rather than containing architecturally separate components. https://en.wikipedia.org/wiki/Monolithic_system
  • 6. Monolithic architecture Storefront UI Backoffice UI Catalog Service User Service Order Service (...) Database Mobile Web API
  • 8. REST REST has become the default technology to support Microservices Architecture ● It's HTTP(S) ● Use HTTP Verbs for actions: GET, PUT, POST, DELETE, PATCH, ... ● Use HTTP Status Codes to provide meaningful and normalized responses to clients ● Easily extensible using HTTP Headers ● Support multiple authentication mechanisms ● JSON is more simple and less verbose than XML
  • 9. The growth of a Microservice Application
  • 10. Ecosystem User interfacePublic API Backend Services Publish / Subscribe Databases BLOB Storage 3rd party systems
  • 11. Component Dependency System Complexity ~= Business Complexity Loose coupling ; High dependency
  • 12. Dependency level = 0 Dependency level = 10 Dependency level = 7 Teams & Components
  • 13. Combine dependency level with ● Development environment ○ Setup ○ Maintain ● Keep services up to date ● Keep database schema and data ● Test ○ Time it takes to finish tests ○ Dependency from data ● CI/CD ○ Keep a stable environment for end-to-end tests ● Contract stability ● Communication between maintainers
  • 15. Terminology Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example). Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Spies are stubs that also record some information based on how they were called. One form of this might be an email service that records how many messages it was sent. Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive. https://martinfowler.com/articles/mocksArentStubs.html
  • 16. Mock your dependencies Dependencies with real implementations are replaced by mocked implementations that provide similar behavior at the interface level.
  • 19. Fake Techniques - Client Fake Client App XptoAPIClient Xpto Web API HTTP FakeXptoAPI Client IXptoApiClient Quick to implement and simple to use No new components on the system Using a Mock framework allows control of results on automated tests Doesn't test the HTTP layer Requires coding to implement statefulness The Production Code is not stimulated Potential risk to "Go Live" with the Fake instead of Real implementation
  • 20. Fake Techniques - Proxy Client App XptoAPIClient Xpto Web API HTTP Quick to implement and simple to use Saved responses are similar to the real API No coding necessary (although possible) Easy to implement with containers Very flexible: easy to modify responses Contract changes invalidate previous saved responses Requires coding to implement statefulness Difficult to implement Expectations mechanism to integrated with automated tests Store and Forward Proxy HTTP Responses
  • 21. Fake Techniques - Fake Server Client App XptoAPIClient Xpto Web API HTTP Not so flexible to change responses Requires coding Need to implement Expectations to integrate with automated tests Code generation accelerates development Easy support for contract changes: (just regenerate the code and change implementation) Easy to create and share containers Easy to implement statefulness Fake Xpto Web API Production&Integration Development&Tests HTTP
  • 23. Demo - Proxy Movie Rating UI MovieRating APIClient Movie Rating Web API HTTP Store and Forward Proxy Responses Omdb API
  • 25. Demo - Fake Server Movie Rating UI MovieRating APIClient Movie Rating Web API Fake Xpto Web API Omdb API
  • 27. Integrating with docker Using docker to launch every 1st dependency allows easy setup of the project. $> git clone <repo> $> docker-compose up deps Open solution in Visual Studio and hit F5 No expensive setup of databases, messaging systems or other services Docker images can be versioned alongside with the versions of the API Can be used to run component tests (not integration tests)
  • 28. Summary ● Fake the 1st level dependencies to avoid having the entire dependency tree ● Choose your strategy: Client Fake, Proxy, Stateful Fake or any other that suits ● Consider generating as much code as possible ● Potentially high upfront investment - big gains in the long run ● Make it easy for the developers to ○ Run the project ○ Manage the versions of the dependencies they are using ○ Write automated tests ● Make components tests running against Fakes instead
  • 31. Patrocinadores “GOLD” Twitter: @PTMicrosoft http://www.microsoft.com/portugal
  • 32. Patrocinadores “GOLD” Twitter: @FindmoreC http://www.findmore.pt/pt
  • 35. http://bit.ly/netponto-aval-76 * Para quem não puder preencher durante a reunião, iremos enviar um email com o link à tarde
  • 36. Próximas reuniões presenciais 07/04/2018 – Lisboa 23/06/2018 – Lisboa 15/09/2018 – Lisboa 24/11/2018 – Lisboa Reserva estes dias na agenda! :)