What is the best approach to tdd

Luca Mattia Ferrari
Luca Mattia FerrariEMEA Solution Architect en Red Hat
What’s the best approach to
TDD?
Luca Ferrari
EMEA SSA for API
Management
Sergio Gutierrez Romero
EMEA SSA for API
Management
2
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
4
What can you expect during this session:
➔ Introductions
➔ Context
➔ TDD foundations
➔ Tools
➔ Stub, Mock, Service Virtualization
➔ API contract first approach
➔ Key takeaways
➔ Where next
2019 RED HAT TECH EXCHANGE
5
Introduction
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
Introductions
6
Name:
Luca Ferrari
Role/team:
EMEA SSA
Where you’re from:
Barcelona & Pavia
Name:
Sergio Gutierrez Romero
Role/team:
EMEA SSA
Where you’re from:
Barcelona
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
7
WHY am I here?
In the news
2019 RED HAT TECH EXCHANGE
8
Context
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
9
Agile Integration foundations
DISTRIBUTED
INTEGRATION
CONTAINERS APIs
LIGHTWEIGHT
PATTERN BASED
EVENT-ORIENTED
COMMUNITY-SOURCED
CLOUD-NATIVE SOLUTIONS
LEAN ARTIFACTS, INDIVIDUALLY
DEPLOYABLE
CONTAINER-BASED SCALING & HIGH
AVAILABILITY
WELL-DEFINED, REUSABLE, &
WELL-MANAGED
ENDPOINTS
ECOSYSTEM LEVERAGE
API
SERVICES
SECURITY, AUTHENTICATION, AUDIT (RH-SSO)
RED HAT
FUSE
RED HAT
AMQ
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
10
Red Hat API Lifecycle
3. MOCK
4. TEST
5. IMPLEMENT
6. DEPLOY
7. SECURE
8. MANAGE
9. DISCOVER
10. DEVELOP
11. CONSUME
12. MONITOR
13. MONETIZE
1. STRATEGY
2. DESIGN
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
11
Red Hat API Lifecycle
Microcks
MOCK
TEST
IMPLEMENT
DEPLOY
SECURE
M
ANAGE
DISCOVER DEVELOP
CONSUME
MONITOR
MONETIZE
API Model Canvas
STRATEGY
DESIGN
SINGLE SIGN-ON (SSO)
2019 RED HAT TECH EXCHANGE
12
Foundations
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
13
TDD Foundations
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
14
TDD Foundations
“Best of” software testing:
● No test at all (!!!)
● Manual tests
● Automated tests on customer irrelevant scenarios
● Automated tests introduced late in the process
● Test are dedicated leftover time
● Lack of communication in the team
● No code refactoring because:
○ Software will break
○ Cost will be too high
○ Software will not be delivered on time
○ Software is not documented
● Cannot rely on test phase for production
● Long regression tests
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
15
TDD Foundations
Test Driven Development is a simple procedure of writing tests before the implementation.
In practice a repetition of a very short development cycle:
1. Write a test.
2. Run all tests.
3. Write the implementation code.
4. Run all tests.
5. Refactor.
6. Run all tests.
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
16
TDD Cycle
REFACTOR
Eliminate
redundancies
RED
Write a test that fails
GREEN
Make the code work
TDD
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
17
TDD Foundations
Software testing
White-box testingBlack-box testing
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
MOCKING:
If it can be easily mocked then it is well structured
EXECUTABLE DOCUMENTATION:
Main problem with software documentation is not up to date and inevitably gets outdated.
Assuming that Continuous Integration (CI) is in use, if some part of test-documentation is
incorrect, it will fail and be fixed
If all functionality is defined as tests before the implementation and execution of all tests is
successful, then tests act as a complete and up-to-date information
NO DEBUGGING:
When tests are written before the code and the code coverage is high, we can have high
confidence that the application works as expected. This does not mean that applications
written using TDD do not have bugs, all applications do. When that happens, it is easy to
isolate them by simply looking for the code that is not covered with tests.
18
TDD Cycle
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
19
TDD Cycle
Don’t want test to focus on external components
Don’t want to add external dependencies to my code
Want to find the defect fast
Want to make the test predictable
Want the test to be fast (fail or succeed)
.
.
.
.
.
BUT eventually I will want to have an integration test covering corner conditions as well
Mocking Phase
2019 RED HAT TECH EXCHANGE
20
Tools
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
21
TDD Tools
Several tools can be helpful for the specific purpose of TDD:
● Git
● Virtual machines / containers
● Build tools
● Integrated Development Environment
● Unit testing frameworks
● Code coverage tools
● Mocking frameworks
● User interface testing
● Behavior-Driven Development
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
22
TDD Tools
Several tools can be helpful for the specific purpose of TDD:
● Git
● Virtual machines / containers
● Build tools
● Integrated Development Environment
● Unit testing frameworks
● Code coverage tools
● Mocking frameworks
● User interface testing
● Behavior-Driven Development - Cucumber
Agile process where the requirement is written so
that everyone (business or developer) understands
it. Requirements are grouped in user stories.
Stories are written by the whole team and used as
both requirements and executable test cases. It
allows to describe and test functionality in (almost)
natural language and makes it runnable and
repeatable.
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
23
Design phase
If it's not testable, it's not designed well
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
24
Design phase
If it's not testable, it's not designed well
Principles:
● You Ain't Gonna Need It (YAGNI)
● Don't Repeat Yourself (DRY)
● Keep It Simple, Stupid (KISS)
● Occam's Razor
● SOLID Single responsibility principle
Open-closed principle
Liskov substitution principle
Interface segregation principle
Dependency inversion principle
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
25
Design phase
2019 RED HAT TECH EXCHANGE
26
Mocking phase
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
27
Stub VS Mock VS Virtual Service
Stub: a minimal implementation of an interface that normally returns hardcoded data that is
tightly coupled to the test suite. A stub is normally written by a developer for personal use
Mock: a programmable interface observer, that verifies outputs against expectations
defined by the test. Mock provides responses based on a given request satisfying
predefined criteria (also called request or parameter matching). A mock also focuses on
interactions rather than state so mocks are usually stateful.
Virtual service: a test double, always called remotely. A virtual service is often created by
recording traffic instead of building the interaction pattern from scratch based on interface
or API documentation. A virtual service can be used to establish a common ground for teams
to communicate and facilitate artifact sharing with other development teams. It can also
simulate non-functional characteristics of systems such as response times or slow
connection
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
28
Stub VS Mock VS Virtual Service
STUB MOCK VIRTUAL SERVICE
Data source Hardcoded data Data setup by tests Recorded data
Invocation protocol Usually in the same process,
sometimes over HTTP or TCP
Most of the time over HTTP or
TCP
Always over the network
Created by Devs and sometimes testers Devs and sometimes testers Mostly testers
Stateful No Yes Yes
2019 RED HAT TECH EXCHANGE
29
Stubbing
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
30
Stubbing
Anybody fancy a
popular mock framework which can be used in conjunction with JUnit. Allows you to create
and configure mock objects. Simplifies the development of tests for classes with external
dependencies.
● Mock away external dependencies and insert the mocks into the code under test
● Execute the code under test
● Validate that the code executed correctly
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
31
@Entity
public class Customer {
@Id
@GeneratedValue(strategy =
GenerationType.AUTO)
private long id;
private String firstName;
private String lastName;
//...getters and setters redacted for
brevity...
}
public class CustomerReader {
@PersistenceContext
private EntityManager entityManager;
public String findFullName(Long customerID){
Customer customer =
entityManager.find(Customer.class, customerID);
return customer.getFirstName() +"
"+customer.getLastName();
}
}
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
32
public class CustomerReaderTest {
//Class to be tested
private CustomerReader customerReader;
//Dependencies
private EntityManager entityManager;
@Before
public void setup(){
customerReader = new CustomerReader();
entityManager = mock(EntityManager.class);
customerReader.setEntityManager(entityManager);
}
@Test
public void happyPathScenario(){
Customer sampleCustomer = new Customer();
sampleCustomer.setFirstName("Susan");
sampleCustomer.setLastName("Ivanova");
when(entityManager.find(Customer.class,1L)).thenReturn(sampleCustomer);
String fullName = customerReader.findFullName(1L);
assertEquals("Susan Ivanova",fullName);
}
@Test
public void customerNotPresentInDb(){
when(entityManager.find(Customer.class,1L)).thenReturn(null);
String fullName = customerReader.findFullName(1L);
assertEquals("",fullName);
}
}
2019 RED HAT TECH EXCHANGE
33
Mocking
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
34
Mocking
Multi-type of Services / API
support
Usable by functional experts,
comprehensive UI
Mock support and ability to deploy
at scale
Ability to use specifications for
running tests
http://microcks.github.io
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
35
Mocking
Service
Contract
Service
Consumer
Development
Test &
Release
Specification
Service
Provider
Build and deploy your
Services / API mocks for
you !
CI / CD
Use mocks for external
dependencies for easier Integration
Testing
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
36
Mocking
Service
Contract Development
Test &
Release
Service
Provider
Test your deployed services and
validate expectations
CI / CD Pipeline
QADev
Smoke tests, Functional tests on
different environments. Record
exchanges for tracking differences.
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
37
Mocking
MICROCKS
APICURIO
2019 RED HAT TECH EXCHANGE
38
Service
Virtualization
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
39
Service virtualization
Predicting the Unpredictable!
Mock APIs
TESTING PREDICTABLE MODEL
Test cases Mock APIs
TESTING THE UNPREDICTABLE
Network Latency
Partial Outage and Cascading
failures
Traffic Spikes
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
40
Service virtualization
Imitation of the REAL API or Mocking on Steroid
Best practices:
1. Use realistic data
2. Isolate API methods
3. Test various response and error codes
4. Simulate network condition and server capacity
5. Do the load on virtual APIs (first)
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
Can everything be virtualized?
41
Service virtualization
https://www.networkworld.com/article/2344791/kellogg-s--lego-team-up-to-trai
n-kids-to-choke.html
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
42
Service virtualization tools
Tools
44
● Hoverfly
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
45
Service virtualization tools ?
Tools
46
● Hoverfly
● Istio Traffic
Mirroring
https://istio.io/blog/2018/traffic-mirroring/
2019 RED HAT TECH EXCHANGE
47
API Contracts
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
Microservice
architecture
48
API Contract First
Moving to Agile
development
Speed of
development
Quality affected
Need automated
testing
TDD approach
API Contract
First
2019 RED HAT TECH EXCHANGE
49
Outro
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
50
Key takeaways
❏ Know the difference between stub, mock and service virtualization
❏ Understand the advantages of TDD and API-contract-first approaches
❏ Know which Open Source tools can be used
CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE
51
Resources
Go, use and contribute to Microcks: http://microcks.github.io/
Roadmap themes for Microcks:
● Tekton integration
● Better integration with APICURIO
● Async API support
We have Microcks customers as well:
● Societe Generale
● EDF
Try Day In a Life workshop: https://mojo.redhat.com/docs/DOC-1189138
As reference for most of the content I used this book:
https://www.amazon.com/Test-Driven-Java-Development-Viktor-Farcic-ebook/dp/B00YS
IM3SC
linkedin.com/company/red-hat
youtube.com/user/RedHatVideos
facebook.com/redhatinc
twitter.com/RedHat
Red Hat is the world’s leading provider of enterprise
open source software solutions. Award-winning
support, training, and consulting services make
Red Hat a trusted adviser to the Fortune 500.
Thank you
53
1 de 49

Recomendados

Availability of Kafka - Beyond the Brokers | Andrew Borley and Emma Humber, IBM por
Availability of Kafka - Beyond the Brokers | Andrew Borley and Emma Humber, IBMAvailability of Kafka - Beyond the Brokers | Andrew Borley and Emma Humber, IBM
Availability of Kafka - Beyond the Brokers | Andrew Borley and Emma Humber, IBMHostedbyConfluent
403 vistas28 diapositivas
Fan-out, fan-in & the multiplexer: Replication recipes for global platform di... por
Fan-out, fan-in & the multiplexer: Replication recipes for global platform di...Fan-out, fan-in & the multiplexer: Replication recipes for global platform di...
Fan-out, fan-in & the multiplexer: Replication recipes for global platform di...HostedbyConfluent
1.5K vistas30 diapositivas
Lessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, Cloudera por
Lessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, ClouderaLessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, Cloudera
Lessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, ClouderaHostedbyConfluent
330 vistas17 diapositivas
Beyond the Brokers | Emma Humber and Andrew Borley, IBM por
Beyond the Brokers | Emma Humber and Andrew Borley, IBMBeyond the Brokers | Emma Humber and Andrew Borley, IBM
Beyond the Brokers | Emma Humber and Andrew Borley, IBMHostedbyConfluent
329 vistas28 diapositivas
Why Kafka Works the Way It Does (And Not Some Other Way) | Tim Berglund, Conf... por
Why Kafka Works the Way It Does (And Not Some Other Way) | Tim Berglund, Conf...Why Kafka Works the Way It Does (And Not Some Other Way) | Tim Berglund, Conf...
Why Kafka Works the Way It Does (And Not Some Other Way) | Tim Berglund, Conf...HostedbyConfluent
298 vistas13 diapositivas
Introducing Events and Stream Processing into Nationwide Building Society (Ro... por
Introducing Events and Stream Processing into Nationwide Building Society (Ro...Introducing Events and Stream Processing into Nationwide Building Society (Ro...
Introducing Events and Stream Processing into Nationwide Building Society (Ro...confluent
1.4K vistas14 diapositivas

Más contenido relacionado

La actualidad más candente

Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe... por
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...HostedbyConfluent
657 vistas35 diapositivas
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.io por
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.ioKickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.io
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.ioHostedbyConfluent
61 vistas22 diapositivas
Apache Kafka from 0.7 to 1.0, History and Lesson Learned por
Apache Kafka from 0.7 to 1.0, History and Lesson LearnedApache Kafka from 0.7 to 1.0, History and Lesson Learned
Apache Kafka from 0.7 to 1.0, History and Lesson LearnedGuozhang Wang
1.5K vistas120 diapositivas
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ) por
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)confluent
126 vistas31 diapositivas
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka... por
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...HostedbyConfluent
3.2K vistas18 diapositivas
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL... por
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...HostedbyConfluent
802 vistas15 diapositivas

La actualidad más candente(20)

Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe... por HostedbyConfluent
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
Not Your Mother's Kafka - Deep Dive into Confluent Cloud Infrastructure | Gwe...
HostedbyConfluent657 vistas
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.io por HostedbyConfluent
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.ioKickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.io
Kickstart your Kafka with Faker Data | Francesco Tisiot, Aiven.io
HostedbyConfluent61 vistas
Apache Kafka from 0.7 to 1.0, History and Lesson Learned por Guozhang Wang
Apache Kafka from 0.7 to 1.0, History and Lesson LearnedApache Kafka from 0.7 to 1.0, History and Lesson Learned
Apache Kafka from 0.7 to 1.0, History and Lesson Learned
Guozhang Wang1.5K vistas
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ) por confluent
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)
confluent126 vistas
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka... por HostedbyConfluent
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...
Kafka error handling patterns and best practices | Hemant Desale and Aruna Ka...
HostedbyConfluent3.2K vistas
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL... por HostedbyConfluent
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...
HostedbyConfluent802 vistas
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J... por HostedbyConfluent
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
HostedbyConfluent426 vistas
A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ... por HostedbyConfluent
A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ...A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ...
A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ...
HostedbyConfluent840 vistas
Using Kafka as a Database For Real-Time Transaction Processing | Chad Preisle... por HostedbyConfluent
Using Kafka as a Database For Real-Time Transaction Processing | Chad Preisle...Using Kafka as a Database For Real-Time Transaction Processing | Chad Preisle...
Using Kafka as a Database For Real-Time Transaction Processing | Chad Preisle...
HostedbyConfluent780 vistas
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix por HostedbyConfluent
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, NutanixGuaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix
Guaranteed Event Delivery with Kafka and NodeJS | Amitesh Madhur, Nutanix
HostedbyConfluent647 vistas
Migrating from One Cloud Provider to Another (Without Losing Your Data or You... por HostedbyConfluent
Migrating from One Cloud Provider to Another (Without Losing Your Data or You...Migrating from One Cloud Provider to Another (Without Losing Your Data or You...
Migrating from One Cloud Provider to Another (Without Losing Your Data or You...
HostedbyConfluent1.4K vistas
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L... por HostedbyConfluent
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
HostedbyConfluent412 vistas
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ... por confluent
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
confluent5.7K vistas
How Zillow Unlocked Kafka to 50 Teams in 8 months | Shahar Cizer Kobrinsky, Z... por HostedbyConfluent
How Zillow Unlocked Kafka to 50 Teams in 8 months | Shahar Cizer Kobrinsky, Z...How Zillow Unlocked Kafka to 50 Teams in 8 months | Shahar Cizer Kobrinsky, Z...
How Zillow Unlocked Kafka to 50 Teams in 8 months | Shahar Cizer Kobrinsky, Z...
HostedbyConfluent577 vistas
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect... por HostedbyConfluent
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
HostedbyConfluent418 vistas
One Click Streaming Data Pipelines & Flows | Leveraging Kafka & Spark | Ido F... por HostedbyConfluent
One Click Streaming Data Pipelines & Flows | Leveraging Kafka & Spark | Ido F...One Click Streaming Data Pipelines & Flows | Leveraging Kafka & Spark | Ido F...
One Click Streaming Data Pipelines & Flows | Leveraging Kafka & Spark | Ido F...
HostedbyConfluent246 vistas
Give Your Confluent Platform Superpowers! (Sandeep Togrika, Intel and Bert Ha... por HostedbyConfluent
Give Your Confluent Platform Superpowers! (Sandeep Togrika, Intel and Bert Ha...Give Your Confluent Platform Superpowers! (Sandeep Togrika, Intel and Bert Ha...
Give Your Confluent Platform Superpowers! (Sandeep Togrika, Intel and Bert Ha...
HostedbyConfluent713 vistas
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an... por confluent
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
confluent803 vistas
Multi-DC Kafka por confluent
Multi-DC KafkaMulti-DC Kafka
Multi-DC Kafka
confluent283 vistas

Similar a What is the best approach to tdd

AzureDay Kyiv 2016 Release Management por
AzureDay Kyiv 2016 Release ManagementAzureDay Kyiv 2016 Release Management
AzureDay Kyiv 2016 Release ManagementSergii Kryshtop
840 vistas43 diapositivas
Improve Code Quality and Time to Market: 100% Cloud-Based Development Workflow por
Improve Code Quality and Time to Market: 100% Cloud-Based Development WorkflowImprove Code Quality and Time to Market: 100% Cloud-Based Development Workflow
Improve Code Quality and Time to Market: 100% Cloud-Based Development WorkflowAcquia
218 vistas62 diapositivas
Continuous Delivery for Machine Learning por
Continuous Delivery for Machine LearningContinuous Delivery for Machine Learning
Continuous Delivery for Machine LearningThoughtworks
1.6K vistas50 diapositivas
Understanding Unit Testing por
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
6.2K vistas27 diapositivas
Agile Bodensee - Testautomation & Continuous Delivery Workshop por
Agile Bodensee - Testautomation & Continuous Delivery WorkshopAgile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery WorkshopMichael Palotas
1.1K vistas94 diapositivas
PMI-ACP Lesson 06 Quality por
PMI-ACP Lesson 06 QualityPMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 QualityThanh Nguyen
694 vistas31 diapositivas

Similar a What is the best approach to tdd(20)

AzureDay Kyiv 2016 Release Management por Sergii Kryshtop
AzureDay Kyiv 2016 Release ManagementAzureDay Kyiv 2016 Release Management
AzureDay Kyiv 2016 Release Management
Sergii Kryshtop840 vistas
Improve Code Quality and Time to Market: 100% Cloud-Based Development Workflow por Acquia
Improve Code Quality and Time to Market: 100% Cloud-Based Development WorkflowImprove Code Quality and Time to Market: 100% Cloud-Based Development Workflow
Improve Code Quality and Time to Market: 100% Cloud-Based Development Workflow
Acquia218 vistas
Continuous Delivery for Machine Learning por Thoughtworks
Continuous Delivery for Machine LearningContinuous Delivery for Machine Learning
Continuous Delivery for Machine Learning
Thoughtworks1.6K vistas
Understanding Unit Testing por ikhwanhayat
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
ikhwanhayat6.2K vistas
Agile Bodensee - Testautomation & Continuous Delivery Workshop por Michael Palotas
Agile Bodensee - Testautomation & Continuous Delivery WorkshopAgile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery Workshop
Michael Palotas1.1K vistas
PMI-ACP Lesson 06 Quality por Thanh Nguyen
PMI-ACP Lesson 06 QualityPMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 Quality
Thanh Nguyen694 vistas
Open Source Power Tools - Opensouthcode 2018-06-02 por Jorge Hidalgo
Open Source Power Tools - Opensouthcode 2018-06-02Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02
Jorge Hidalgo803 vistas
Transform Digital Business with DevOps por Daniel Oh
Transform Digital Business with DevOpsTransform Digital Business with DevOps
Transform Digital Business with DevOps
Daniel Oh551 vistas
Indy meetup#7 effective unit-testing-mule por ikram_ahamed
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
ikram_ahamed376 vistas
MACHINE LEARNING AUTOMATIONS PIPELINE WITH CI/CD por IRJET Journal
MACHINE LEARNING AUTOMATIONS PIPELINE WITH CI/CDMACHINE LEARNING AUTOMATIONS PIPELINE WITH CI/CD
MACHINE LEARNING AUTOMATIONS PIPELINE WITH CI/CD
IRJET Journal4 vistas
Dublin Unity User Group Meetup Sept 2015 por Dominique Boutin
Dublin Unity User Group Meetup Sept 2015Dublin Unity User Group Meetup Sept 2015
Dublin Unity User Group Meetup Sept 2015
Dominique Boutin700 vistas
Industrializing Machine learning pipelines por Germain Tanguy
Industrializing Machine learning pipelinesIndustrializing Machine learning pipelines
Industrializing Machine learning pipelines
Germain Tanguy1.2K vistas
PureApplication: Devops and Urbancode por John Hawkins
PureApplication: Devops and UrbancodePureApplication: Devops and Urbancode
PureApplication: Devops and Urbancode
John Hawkins974 vistas
Delivery Pipelines as a First Class Citizen @deliverAgile2019 por ciberkleid
Delivery Pipelines as a First Class Citizen @deliverAgile2019Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019
ciberkleid2.9K vistas
Multilanguage Pipelines with Jenkins, Docker and Kubernetes (Commit Conf 2018) por Jorge Hidalgo
Multilanguage Pipelines with Jenkins, Docker and Kubernetes (Commit Conf 2018)Multilanguage Pipelines with Jenkins, Docker and Kubernetes (Commit Conf 2018)
Multilanguage Pipelines with Jenkins, Docker and Kubernetes (Commit Conf 2018)
Jorge Hidalgo221 vistas
Developing ML-enabled Data Pipelines on Databricks using IDE & CI/CD at Runta... por Databricks
Developing ML-enabled Data Pipelines on Databricks using IDE & CI/CD at Runta...Developing ML-enabled Data Pipelines on Databricks using IDE & CI/CD at Runta...
Developing ML-enabled Data Pipelines on Databricks using IDE & CI/CD at Runta...
Databricks262 vistas
Software Testing - Online Guide por bigspire
Software Testing - Online GuideSoftware Testing - Online Guide
Software Testing - Online Guide
bigspire659 vistas
Why we should consider Open Hybrid Cloud.pdf por Masahiko Umeno
Why we should  consider Open Hybrid Cloud.pdfWhy we should  consider Open Hybrid Cloud.pdf
Why we should consider Open Hybrid Cloud.pdf
Masahiko Umeno30 vistas

Más de Luca Mattia Ferrari

Meetup 2023 - Gateway API.pdf por
Meetup 2023 - Gateway API.pdfMeetup 2023 - Gateway API.pdf
Meetup 2023 - Gateway API.pdfLuca Mattia Ferrari
12 vistas36 diapositivas
Meetup 2022 - APIs with Quarkus.pdf por
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfLuca Mattia Ferrari
27 vistas23 diapositivas
Meetup 2022 - API Gateway landscape.pdf por
Meetup 2022 - API Gateway landscape.pdfMeetup 2022 - API Gateway landscape.pdf
Meetup 2022 - API Gateway landscape.pdfLuca Mattia Ferrari
46 vistas28 diapositivas
APIs at the Edge por
APIs at the EdgeAPIs at the Edge
APIs at the EdgeLuca Mattia Ferrari
17 vistas46 diapositivas
Opa in the api management world por
Opa in the api management worldOpa in the api management world
Opa in the api management worldLuca Mattia Ferrari
144 vistas40 diapositivas
How easy (or hard) it is to monitor your graph ql service performance por
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceLuca Mattia Ferrari
140 vistas35 diapositivas

Más de Luca Mattia Ferrari(20)

How easy (or hard) it is to monitor your graph ql service performance por Luca Mattia Ferrari
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
Luca Mattia Ferrari140 vistas
Leverage event streaming framework to build intelligent applications por Luca Mattia Ferrari
Leverage event streaming framework to build intelligent applicationsLeverage event streaming framework to build intelligent applications
Leverage event streaming framework to build intelligent applications
statement of accomplishment - heterogeneous parallel programming por Luca Mattia Ferrari
statement of accomplishment - heterogeneous parallel programmingstatement of accomplishment - heterogeneous parallel programming
statement of accomplishment - heterogeneous parallel programming
Luca Mattia Ferrari239 vistas

Último

Ports-and-Adapters Architecture for Embedded HMI por
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
6 vistas19 diapositivas
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... por
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Lisi Hocke
30 vistas124 diapositivas
FOSSLight Community Day 2023-11-30 por
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30Shane Coughlan
5 vistas18 diapositivas
Navigating container technology for enhanced security by Niklas Saari por
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariMetosin Oy
14 vistas34 diapositivas
Headless JS UG Presentation.pptx por
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptxJack Spektor
7 vistas24 diapositivas
Dapr Unleashed: Accelerating Microservice Development por
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice DevelopmentMiroslav Janeski
10 vistas29 diapositivas

Último(20)

Ports-and-Adapters Architecture for Embedded HMI por Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert6 vistas
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... por Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke30 vistas
FOSSLight Community Day 2023-11-30 por Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan5 vistas
Navigating container technology for enhanced security by Niklas Saari por Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 vistas
Headless JS UG Presentation.pptx por Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 vistas
Dapr Unleashed: Accelerating Microservice Development por Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski10 vistas
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action por Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 vistas
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 vistas
The Era of Large Language Models.pptx por AbdulVahedShaik
The Era of Large Language Models.pptxThe Era of Large Language Models.pptx
The Era of Large Language Models.pptx
AbdulVahedShaik5 vistas
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... por Deltares
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
Deltares5 vistas
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... por NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi28 vistas
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... por Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri825 vistas
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols por Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares7 vistas
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... por Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 vistas
Software evolution understanding: Automatic extraction of software identifier... por Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Airline Booking Software por SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta6 vistas

What is the best approach to tdd

  • 1. What’s the best approach to TDD? Luca Ferrari EMEA SSA for API Management Sergio Gutierrez Romero EMEA SSA for API Management 2
  • 2. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 4 What can you expect during this session: ➔ Introductions ➔ Context ➔ TDD foundations ➔ Tools ➔ Stub, Mock, Service Virtualization ➔ API contract first approach ➔ Key takeaways ➔ Where next
  • 3. 2019 RED HAT TECH EXCHANGE 5 Introduction
  • 4. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE Introductions 6 Name: Luca Ferrari Role/team: EMEA SSA Where you’re from: Barcelona & Pavia Name: Sergio Gutierrez Romero Role/team: EMEA SSA Where you’re from: Barcelona
  • 5. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 7 WHY am I here? In the news
  • 6. 2019 RED HAT TECH EXCHANGE 8 Context
  • 7. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 9 Agile Integration foundations DISTRIBUTED INTEGRATION CONTAINERS APIs LIGHTWEIGHT PATTERN BASED EVENT-ORIENTED COMMUNITY-SOURCED CLOUD-NATIVE SOLUTIONS LEAN ARTIFACTS, INDIVIDUALLY DEPLOYABLE CONTAINER-BASED SCALING & HIGH AVAILABILITY WELL-DEFINED, REUSABLE, & WELL-MANAGED ENDPOINTS ECOSYSTEM LEVERAGE API SERVICES SECURITY, AUTHENTICATION, AUDIT (RH-SSO) RED HAT FUSE RED HAT AMQ
  • 8. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 10 Red Hat API Lifecycle 3. MOCK 4. TEST 5. IMPLEMENT 6. DEPLOY 7. SECURE 8. MANAGE 9. DISCOVER 10. DEVELOP 11. CONSUME 12. MONITOR 13. MONETIZE 1. STRATEGY 2. DESIGN
  • 9. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 11 Red Hat API Lifecycle Microcks MOCK TEST IMPLEMENT DEPLOY SECURE M ANAGE DISCOVER DEVELOP CONSUME MONITOR MONETIZE API Model Canvas STRATEGY DESIGN SINGLE SIGN-ON (SSO)
  • 10. 2019 RED HAT TECH EXCHANGE 12 Foundations
  • 11. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 13 TDD Foundations
  • 12. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 14 TDD Foundations “Best of” software testing: ● No test at all (!!!) ● Manual tests ● Automated tests on customer irrelevant scenarios ● Automated tests introduced late in the process ● Test are dedicated leftover time ● Lack of communication in the team ● No code refactoring because: ○ Software will break ○ Cost will be too high ○ Software will not be delivered on time ○ Software is not documented ● Cannot rely on test phase for production ● Long regression tests
  • 13. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 15 TDD Foundations Test Driven Development is a simple procedure of writing tests before the implementation. In practice a repetition of a very short development cycle: 1. Write a test. 2. Run all tests. 3. Write the implementation code. 4. Run all tests. 5. Refactor. 6. Run all tests.
  • 14. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 16 TDD Cycle REFACTOR Eliminate redundancies RED Write a test that fails GREEN Make the code work TDD
  • 15. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 17 TDD Foundations Software testing White-box testingBlack-box testing
  • 16. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE MOCKING: If it can be easily mocked then it is well structured EXECUTABLE DOCUMENTATION: Main problem with software documentation is not up to date and inevitably gets outdated. Assuming that Continuous Integration (CI) is in use, if some part of test-documentation is incorrect, it will fail and be fixed If all functionality is defined as tests before the implementation and execution of all tests is successful, then tests act as a complete and up-to-date information NO DEBUGGING: When tests are written before the code and the code coverage is high, we can have high confidence that the application works as expected. This does not mean that applications written using TDD do not have bugs, all applications do. When that happens, it is easy to isolate them by simply looking for the code that is not covered with tests. 18 TDD Cycle
  • 17. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 19 TDD Cycle Don’t want test to focus on external components Don’t want to add external dependencies to my code Want to find the defect fast Want to make the test predictable Want the test to be fast (fail or succeed) . . . . . BUT eventually I will want to have an integration test covering corner conditions as well Mocking Phase
  • 18. 2019 RED HAT TECH EXCHANGE 20 Tools
  • 19. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 21 TDD Tools Several tools can be helpful for the specific purpose of TDD: ● Git ● Virtual machines / containers ● Build tools ● Integrated Development Environment ● Unit testing frameworks ● Code coverage tools ● Mocking frameworks ● User interface testing ● Behavior-Driven Development
  • 20. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 22 TDD Tools Several tools can be helpful for the specific purpose of TDD: ● Git ● Virtual machines / containers ● Build tools ● Integrated Development Environment ● Unit testing frameworks ● Code coverage tools ● Mocking frameworks ● User interface testing ● Behavior-Driven Development - Cucumber Agile process where the requirement is written so that everyone (business or developer) understands it. Requirements are grouped in user stories. Stories are written by the whole team and used as both requirements and executable test cases. It allows to describe and test functionality in (almost) natural language and makes it runnable and repeatable.
  • 21. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 23 Design phase If it's not testable, it's not designed well
  • 22. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 24 Design phase If it's not testable, it's not designed well Principles: ● You Ain't Gonna Need It (YAGNI) ● Don't Repeat Yourself (DRY) ● Keep It Simple, Stupid (KISS) ● Occam's Razor ● SOLID Single responsibility principle Open-closed principle Liskov substitution principle Interface segregation principle Dependency inversion principle
  • 23. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 25 Design phase
  • 24. 2019 RED HAT TECH EXCHANGE 26 Mocking phase
  • 25. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 27 Stub VS Mock VS Virtual Service Stub: a minimal implementation of an interface that normally returns hardcoded data that is tightly coupled to the test suite. A stub is normally written by a developer for personal use Mock: a programmable interface observer, that verifies outputs against expectations defined by the test. Mock provides responses based on a given request satisfying predefined criteria (also called request or parameter matching). A mock also focuses on interactions rather than state so mocks are usually stateful. Virtual service: a test double, always called remotely. A virtual service is often created by recording traffic instead of building the interaction pattern from scratch based on interface or API documentation. A virtual service can be used to establish a common ground for teams to communicate and facilitate artifact sharing with other development teams. It can also simulate non-functional characteristics of systems such as response times or slow connection
  • 26. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 28 Stub VS Mock VS Virtual Service STUB MOCK VIRTUAL SERVICE Data source Hardcoded data Data setup by tests Recorded data Invocation protocol Usually in the same process, sometimes over HTTP or TCP Most of the time over HTTP or TCP Always over the network Created by Devs and sometimes testers Devs and sometimes testers Mostly testers Stateful No Yes Yes
  • 27. 2019 RED HAT TECH EXCHANGE 29 Stubbing
  • 28. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 30 Stubbing Anybody fancy a popular mock framework which can be used in conjunction with JUnit. Allows you to create and configure mock objects. Simplifies the development of tests for classes with external dependencies. ● Mock away external dependencies and insert the mocks into the code under test ● Execute the code under test ● Validate that the code executed correctly
  • 29. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 31 @Entity public class Customer { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String firstName; private String lastName; //...getters and setters redacted for brevity... } public class CustomerReader { @PersistenceContext private EntityManager entityManager; public String findFullName(Long customerID){ Customer customer = entityManager.find(Customer.class, customerID); return customer.getFirstName() +" "+customer.getLastName(); } }
  • 30. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 32 public class CustomerReaderTest { //Class to be tested private CustomerReader customerReader; //Dependencies private EntityManager entityManager; @Before public void setup(){ customerReader = new CustomerReader(); entityManager = mock(EntityManager.class); customerReader.setEntityManager(entityManager); } @Test public void happyPathScenario(){ Customer sampleCustomer = new Customer(); sampleCustomer.setFirstName("Susan"); sampleCustomer.setLastName("Ivanova"); when(entityManager.find(Customer.class,1L)).thenReturn(sampleCustomer); String fullName = customerReader.findFullName(1L); assertEquals("Susan Ivanova",fullName); } @Test public void customerNotPresentInDb(){ when(entityManager.find(Customer.class,1L)).thenReturn(null); String fullName = customerReader.findFullName(1L); assertEquals("",fullName); } }
  • 31. 2019 RED HAT TECH EXCHANGE 33 Mocking
  • 32. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 34 Mocking Multi-type of Services / API support Usable by functional experts, comprehensive UI Mock support and ability to deploy at scale Ability to use specifications for running tests http://microcks.github.io
  • 33. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 35 Mocking Service Contract Service Consumer Development Test & Release Specification Service Provider Build and deploy your Services / API mocks for you ! CI / CD Use mocks for external dependencies for easier Integration Testing
  • 34. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 36 Mocking Service Contract Development Test & Release Service Provider Test your deployed services and validate expectations CI / CD Pipeline QADev Smoke tests, Functional tests on different environments. Record exchanges for tracking differences.
  • 35. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 37 Mocking MICROCKS APICURIO
  • 36. 2019 RED HAT TECH EXCHANGE 38 Service Virtualization
  • 37. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 39 Service virtualization Predicting the Unpredictable! Mock APIs TESTING PREDICTABLE MODEL Test cases Mock APIs TESTING THE UNPREDICTABLE Network Latency Partial Outage and Cascading failures Traffic Spikes
  • 38. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 40 Service virtualization Imitation of the REAL API or Mocking on Steroid Best practices: 1. Use realistic data 2. Isolate API methods 3. Test various response and error codes 4. Simulate network condition and server capacity 5. Do the load on virtual APIs (first)
  • 39. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE Can everything be virtualized? 41 Service virtualization https://www.networkworld.com/article/2344791/kellogg-s--lego-team-up-to-trai n-kids-to-choke.html
  • 40. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 42 Service virtualization tools
  • 42. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 45 Service virtualization tools ?
  • 43. Tools 46 ● Hoverfly ● Istio Traffic Mirroring https://istio.io/blog/2018/traffic-mirroring/
  • 44. 2019 RED HAT TECH EXCHANGE 47 API Contracts
  • 45. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE Microservice architecture 48 API Contract First Moving to Agile development Speed of development Quality affected Need automated testing TDD approach API Contract First
  • 46. 2019 RED HAT TECH EXCHANGE 49 Outro
  • 47. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 50 Key takeaways ❏ Know the difference between stub, mock and service virtualization ❏ Understand the advantages of TDD and API-contract-first approaches ❏ Know which Open Source tools can be used
  • 48. CONFIDENTIAL INTERNAL USE2019 RED HAT TECH EXCHANGE 51 Resources Go, use and contribute to Microcks: http://microcks.github.io/ Roadmap themes for Microcks: ● Tekton integration ● Better integration with APICURIO ● Async API support We have Microcks customers as well: ● Societe Generale ● EDF Try Day In a Life workshop: https://mojo.redhat.com/docs/DOC-1189138 As reference for most of the content I used this book: https://www.amazon.com/Test-Driven-Java-Development-Viktor-Farcic-ebook/dp/B00YS IM3SC
  • 49. linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat Red Hat is the world’s leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you 53