SlideShare a Scribd company logo
1 of 100
@arafkarsh arafkarsh
ARAF KARSH HAMID
Co-Founder / CTO
MetaMagic Global Inc., NJ, USA
@arafkarsh
arafkarsh
1
Microservices
Architecture Series
Building Cloud Native Apps
Testing Strategies
Behavior Driven Design
JUnit 5, Cucumber, Selenium,
Mockito, WireMock, Pact
Part 6 of 11
@arafkarsh arafkarsh 2
Slides are color coded based on the topic colors.
Microservices
Testing Strategies
1
Unit Testing
JUnit 5
2
Behavior Driven
Development
Cucumber, Selenium
Mockito
3
Integration /
Contract Testing
WireMock, Pact
4
@arafkarsh arafkarsh
Agile
Scrum (4-6 Weeks)
Developer Journey
Monolithic
Domain Driven Design
Event Sourcing and CQRS
Waterfall
Optional
Design
Patterns
Continuous Integration (CI)
6/12 Months
Enterprise Service Bus
Relational Database [SQL] / NoSQL
Development QA / QC Ops
3
Microservices
Domain Driven Design
Event Sourcing and CQRS
Scrum / Kanban (1-5 Days)
Mandatory
Design
Patterns
Infrastructure Design Patterns
CI
DevOps
Event Streaming / Replicated Logs
SQL NoSQL
CD
Container Orchestrator Service Mesh
@arafkarsh arafkarsh
Microservices Testing Strategies
• Unit testing
• Component testing
• Integration Contract testing
• Integration testing
4
1
@arafkarsh arafkarsh
Microservices Testing Strategies
5
E2E
Testing
Integration
Testing
Contract Testing
Component Testing
Unit Testing
Number of Tests
Speed
Cost
Time
Mike Cohen’s Testing Pyramid
Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html
70%
20%
10%
Ubiquitous
Language
Domain
Expert
Analyst Developers
QA
Design
Docs
Test Cases
Code
Architect
@arafkarsh arafkarsh
Other Testing Strategies or Anti Patterns
6
Inverted Pyramid /
Ice Cream Cone Strategy
Unit Testing
Integration Testing
End 2 End
Testing
Hour Glass Strategy
70%
20%
10%
45%
45%
10%
@arafkarsh arafkarsh
Microservices Testing Strategy
7
Unit Testing
A unit test exercises the
smallest piece of testable
software in the application
to determine whether it
behaves as expected.
Source: https://martinfowler.com/articles/microservice-testing/#agenda
Component Testing
A component test limits the
scope of the exercised
software to a portion of the
system under test,
manipulating the system
through internal code
interfaces and using test
doubles to isolate the code
under test from other
components.
Integration Testing
An integration test verifies
the communication paths
and interactions between
components to detect
interface defects
Integration Contract Testing
An Integration Contract test is a
test at the boundary of an
external service verifying that it
meets the contract expected by a
consuming service.
End 2 End Testing
An end-to-end test verifies that a
system meets external
requirements and achieves its
goals, testing the entire system,
from end to end
Say NO to End 2 End Tests - Mike
Walker April 22, 2015. Google Test Blog
@arafkarsh arafkarsh
Microservices Testing Scenarios / Tools
8
Testing Tools
Contract Testing Scope
Integration Testing
Verifies the communication
paths and interactions between
components to detect interface
defects
Contract Testing
It is a test at the boundary of an
external service verifying that it
meets the contract expected by a
consuming service.
Payment Mock
Integration
Contract
Testing
Scope
Test Double
Montebank
Cart
Component Testing
Unit
Testing
Integration
Testing
Scope
Order
REST / HTTP or
Events / Kafka
Item ID,
Quantity,
Address..
Mock Order
Component Testing
A component test limits the
scope of the exercised
software to a portion of the
system under test.
Order
Payment
Unit
Testing
Firewall
Integration Testing Scope
REST / HTTP
Payment
Sandbox
Component
Testing
U
@arafkarsh arafkarsh
Junit 5
5.7.2
Cucumber
6.10.4
Mockito
3.11.2
Selenium
4.0.0
WireMock
2.29.1
Pact
4.0.10
9
Source: https://github.com/MetaArivu/ms-order-service
@arafkarsh arafkarsh
Package Structure
10
1. Order Service
2. Payment Service
3. Packing Service
4. Shipping Service
5. Warehouse Service
6. Delivery City Service
Services
1. Order Controller
Controllers
Source: https://github.com/MetaArivu/ms-order-service
@arafkarsh arafkarsh
Order Service API Calls
11
http://localhost:90880/swagger-ui.html
Based on Open API v3
@arafkarsh arafkarsh
JUnit 5
• JUnit 5 Testing
• Annotations
• Tags and Filtering
• Meta Annotations
• Basic Assertions in JUnit 5
• Testing Categories
12
2
@arafkarsh arafkarsh
JUnit 5 – Unit Testing
13
Assert
@BeforeAll
@BeforeEach
@Test
@AfterEach
@AfterAll
System
Under
Test
All the
Test
Cases
Setup
Check
Verify
Teardown
Test Suites
Teardown All
Setup All
@arafkarsh arafkarsh
JUnit 5 – Test Annotations
14
@Test
@RepeatedTest
@ParametrizedTest
@NestedTest
@ValueSource
@EnumSource
@MethodSource
@CsvSource
@CsvFileSource
@ArgumentSource
@DisplayName
Give meaningful name
for your tests
@Tag
Categorize and Filter
your tests.
@Order
Execute your tests in a
specific order.
@Disabled
Disables your test
@arafkarsh arafkarsh
JUnit 5 – Tags and Filtering
15
Functional
Non-Functional
Performance
Usability
Security
Accessibility
Stress
Load
@arafkarsh arafkarsh
JUnit 5 – Meta Annotations
16
Non-Functional
Performance
Load
@arafkarsh arafkarsh
Filtering in POM File using Sure Fire Plugin
1. Using Tags, you can filter specific
tests to get executed in your build
process.
2. For Ex. If you tags like All, Unit,
Components, Contract, and
Integration and you want to run
only Component and Contract
Testing and exclude Non-
Functional Tests. Then
<groups>
Component, Contract
</groups>
<excludedGroups>
Non-Functional
</excludedGroups>
@arafkarsh arafkarsh
Basic Assertions in JUnit 5
18
Assertion Details
fail Fails a test with a given message and or Exception
assertTrue Validates that the supplied Condition is True
assertFalse Validates that the supplied Condition is False
assertNull Validates the the supplied Object is Null
assertEquals Validates that 2 supplied Objects are equal
assertArrayEquals Validates that 2 supplied Arrays are equals
assertIterableEquals Validates that 2 supplied Iterable Objects are equal.
assertLineMatch Validates that 2 lines of Strings are equal.
assertNotEquals Validates that 2 supplied Objects are NOT Equal
assertSame Validates that 2 Object are same – compared with ==
assertNotSame Validates that 2 Objects are not same – compared with !=
@arafkarsh arafkarsh
Assertions in JUnit 5
19
Assertion Details
assertAll Groups different Assertion at the same time
assertThrows
To verify that a given Exception is thrown from piece
of code.
assertTimeout Verifies the timeout of a given operation
assertTimeoutPreemptively If the timeout exceeds then terminated.
3rd Party Assertions
assertThat
An object is matched with a Matcher to see if it
meets the expectation.
@arafkarsh arafkarsh
JUnit 4 >> JUnit 5
20
JUnit 4 JUnit 5
@BeforeClass Executed Before All @Test in the Current Class @BeforeAll
@Before Executed Before each @Test @BeforeEach
@After Executed After Each @Test @AfterEach
@AfterClass Executed After All @Test in the Current Class @AfterAll
@Category To Group the test cases @Tag
@arafkarsh arafkarsh
Junit 5 – Parametrized Tests
21
Value Source
Enum Source
@arafkarsh arafkarsh
JUnit 5 – Parametrized Tests
22
CSV Source
CSV File Source
@arafkarsh arafkarsh
JUnit 5 – Parametrized Tests
23
Method Source
@arafkarsh arafkarsh
JUnit 5 – Parametrized Tests
24
Argument Source
Argument Source Provider
@arafkarsh arafkarsh
JUnit 5 – Nested Tests
25
@arafkarsh arafkarsh
JUnit 5 – Repeated Tests
26
@arafkarsh arafkarsh
Cucumber
Behavior Driven Development
27
3
@arafkarsh arafkarsh
Features of BDD
28
• Focus on Behavior of the System
rather than tests.
• Collaboration between Business
Stake holders, Analysts,
Developers, QA.
• Ubiquitous Language
• Driven By Business Value
• Extends Test Driven Development
https://cucumber.io/
Free and Open-Source Framework for
Java Stack.
Free and Open Source BDD
Framework for .Net Stack
https://specflow.org/
@arafkarsh arafkarsh
Behavior Driven Development
29
Source: https://dannorth.net/introducing-bdd/
As an insurance Broker
I want to know who my Gold Customers are
So that I sell more
Given Customer John Doe exists
When
he buys insurance ABC for
$1000 USD
Then He becomes a Gold Customer
BDD Construct
Role-Feature-Reason Matrix
As a Customer
I want to withdraw Cash from ATM
So that I don’t have to wait in line at the bank
Given
The account is in Credit
AND the Card is Valid
AND the dispenser contains Cash
BDD Construct
Role-Feature-Reason Matrix
When The Customer requests Cash
Then
Ensure that the Account is debited
AND Ensure cash is dispensed
AND ensure that Card is returned.
@arafkarsh arafkarsh
Theme/Epic – Shopping Portal / Cart
30
As a Consumer
I want to Add a Product to Cart
So that I can buy the product
Role-Feature-Reason Matrix
User Story – 1 : Add to Cart
BDD Acceptance Criteria – 1: Add to Cart
Given The user logged into the portal and a Product is
selected and Product details are available
When The user then clicks Add to Cart Button
Then The system will add the Item (Product) into the
card and Updates Item counter in the Cart Icon
AND Saves the Cart information in the DB
AND if the save fails the system shows an Error
“Unable to Add Product to the Cart”.
BDD Acceptance Criteria – 2: Save Cart
Given The Request is authenticated
When The Input contains user login id, product
id
Then The system will add the Item (Product)
into the Cart & Saves the Cart
information in the DB
AND if the save fails the system shows
an Error “Unable to Add Product to the
Cart”.
@arafkarsh arafkarsh
Theme/Epic – Shopping Portal / Customer
31
As a Consumer
I want to Select Shipping Address
So that I can ship the items to that Address
Role-Feature-Reason Matrix
User Story – 3 : Select Address BDD Acceptance Criteria – 1 : Show Address
Given The user in the Shopping Cart Page
When User Clicks Proceed to Buy Button
Then The System shows the Available Address for
Shipping
BDD Acceptance Criteria – 2 : Select Address
Given The user in the Shopping Cart Page with
Available Shipping Address
When User Selects Address and Clicks Proceed to
Buy
Then The System save the Temp Order details
from Items from Shopping and Selected
Shipping Address
AND this details are valid only for the user
session. If the order is not placed Temp
Order items will be put back in Cart DB
BDD Acceptance Criteria – 3 : Save Temp Order
Given The Request is authenticated
When Input contains user login id, items, shipping
address
Then The System save the Temp Order details
from Items from Shopping and Selected
Shipping Address
AND this details are valid only for the user
session. If the order is not placed Temp
Order items will be put back in Cart DB
@arafkarsh arafkarsh
Theme/Epic – Shopping Portal / Order
32
As a Consumer
I want to Process the Order
So that I can buy products
Role-Feature-Reason Matrix
User Story – 1 : Process Order
BDD Acceptance Criteria – 1 : Add Payment
Given The user in the Order Cart Page with Items
and selected Shipping Address
When User Selects Payment Option As Credit Card
AND Input the Credit Card Details in the
following fields Card Name, Card No. Expiry
Date, CVV Number
Then The System Validates the Credit Card
Number and the Expiry Date and Card Name
& CVV Must NOT be Null
IF Invalid Systems says invalid Payment
details else
Saves the info and proceed for payment.
BDD Acceptance Criteria – 3 : Save Payment
Given The Request is authenticated
When Input contains user login id, order id,
payment details (card number only last 4
digits)
Then The System Validates the Credit Card
Number and the Expiry Date and Card Name
and CVV Must NOT be Null
IF Invalid Systems returns invalid Payment
details
ELSE
Saves the following info Card Name, Card
Number (only last 4 digits), Expiry Date
BDD Acceptance Criteria – 3 : Payment Gateway
Given The Request is authenticated
When Input contains Valid payment details
Then With the Valid Payment Details System calls
External Payment Service for Payment
Processing and Returns Result to Calling
System
@arafkarsh arafkarsh
As a Patient
I want to get diagnosed by a Doctor
So that I can be healthy again
Role-Feature-Reason Matrix
User Story – 1 : Patient Diagnosis
BDD Acceptance Criteria – 1 : Show Patient Info
Given The Patient John Doe Exists and has an
Appointment with the doctor
When The Doctor selects the Patient Info
Then The System shows the Patient Info with
following details
Patient Name, Age, Gender, Contact No. and
the Health info contains the following
Pulse, Blood Pressure, Height and Weight
BDD Acceptance Criteria – 2 : Add Diagnosis
Given Patient Details are Available
When Doctor Selects Add Diagnosis
Then The system shows a text area for adding the
diagnosis and the doctor can add multiple
diagnosis.
BDD Acceptance Criteria – 4 : Save Diagnosis
Given The Request is authenticated
When Input contains Patient Diagnosis Details
Then With the Valid Patient Diagnosis Details and
the system will save the data send the
response back to the user.
BDD Acceptance Criteria – 3 : Add Prescription
Given Patient Details & Diagnosis are Available
When Doctor Selects Add Prescription
Then The system shows a text area for adding the
prescription, and the frequency of usage in a
day and for how many days, and the doctor
can add multiple prescription.
Theme/Epic –
Hospital / Diagnosis
33
@arafkarsh arafkarsh
BDD Specs
34
BDD Style Specs for Searching for a
Product in Amazon
@arafkarsh arafkarsh
Cucumber JUnit 4 Integration
35
Specs Definition
Steps for Testing
@arafkarsh arafkarsh
Step Definitions
36
Dependency Injection
@arafkarsh arafkarsh
Specs for Payment Criteria
37
@arafkarsh arafkarsh
Cucumber Junit 4 Integration
38
Specs Definition
Steps for Testing
@arafkarsh arafkarsh
Mockito
Component / Mock / Contract Testing
39
@arafkarsh arafkarsh
Mock Testing Tools Trends for Last 5 Years
40
@arafkarsh arafkarsh
Mockito Concepts
41
Verify
3. Verify Expectations
and Results
Verify Result
1. Set the expectations Expect When()
Then Return()
Use
2. Use the object being
tested
Test your Component
@arafkarsh arafkarsh
Annotation – @Mock, @InjectMock
42
Create Mocks for
1. Repository
2. Payment Service
Inject the Mocks into
Order Service
Scenario
Create Mocks for the following
1. Repository Service
2. Payment Service
Annotations
• @Mock
• @InjectMocks
Test Cases
1. Given a Valid Order
2. Test for Payment Accepted
3. Test for Payment Declined
@arafkarsh arafkarsh
Conditions – when().thenReturn()
43
Test Cases
1. Given a Valid Order
2. Test for Payment Accepted
3. Test for Payment Declined
@arafkarsh arafkarsh
Annotation - @Spy
44
Spy works on the Actual
Implementation
Inject the Mocks
into Order Service
Scenario
Create Mocks for the following
1. Packaging Service
2. Shipping Service
Annotations
• @Spy
• @Mock
• @InjectMocks
Test Cases
1. Given a Valid Paid Order
2. Test for Packaging
3. Test for Shipping
@arafkarsh arafkarsh
Annotation - @Spy
45
Scenario – 1
Create Mocks for the following
1. Packaging Service
2. Shipping Service
Annotations
• @Spy
• @Mock
• @InjectMocks
Test Cases
1. Given a Valid Paid Order
2. Test for Packaging
3. Test for Shipping
@arafkarsh arafkarsh
Annotation – @Spy
46
Scenario – 2
Create Mocks for the following
1. Packaging Service
2. Shipping Service
Annotations
• @Spy
• @Mock
• @InjectMocks
Test Cases
1. Given a Valid Paid Order
2. Test for Packaging
3. Test for Shipping
@arafkarsh arafkarsh
Annotation – @Spy
47
Scenario – 3
Create Mocks for the following
1. Packaging Service
2. Shipping Service
Annotations
• @Spy
• @Mock
• @InjectMocks
Test Cases
1. Given a Valid Paid Order
2. Test for Packaging
3. Test for Shipping
@arafkarsh arafkarsh
Advanced Features
48
Scenario
Shipping Service with Delivery City
Details for the final Shipment
Mockito Advanced Features
1. Ordering the Input – InOrder
2. Argument Matcher
3. Counts
4. Built In Answer
5. Storing Arguments – Captor
6. Throwing Exceptions
@arafkarsh arafkarsh
Advanced Features – InOrder
49
@arafkarsh arafkarsh
Advanced Features – Argument Matcher
50
@arafkarsh arafkarsh
Advanced Features – Count : External Calls
51
@arafkarsh arafkarsh
Advanced Features – Built in Answers
52
@arafkarsh arafkarsh
Advanced Features – Built in Answers
53
@arafkarsh arafkarsh
Advanced Features – Captor : Argument Capture
54
@arafkarsh arafkarsh
Advanced Features – Catching Exception
55
@arafkarsh arafkarsh
SpringBootTest 2
With JUnit 5
56
@arafkarsh arafkarsh
Spring Boot Test
1. Getting Application
Context
2. Auto wiring the
dependencies
3. JUnit 5 Based
Examples
 This is required for
WireMock and Pact
Actual Payment Service
Implementation is loaded
57
@arafkarsh arafkarsh
SpringBootTest POM Config for JUnit 5
58
Exclude Default JUnit 4
SBT v 2.5.3
@arafkarsh arafkarsh
WireMock, Pact
Integration / Contract Testing
59
4
@arafkarsh arafkarsh
WireMock
o Without SpringBootTest
o With SpringBootTest
60
@arafkarsh arafkarsh
WireMock Architecture
61
Service (Client) WireMock
Request Mapping
Response Data
HTTP/S Calls
@arafkarsh arafkarsh
Use Case – Order and Payment Service
62
Worker
Nodes
Order Pod
Order Pod
Order Pod
Order Service
N4
N3
MySQL
DB
EndPoints
N2
Payment Pod
Payment Pod
Payment Pod
Payment
Service
Service Call
Kube DNS
EndPoints
1. Order and Payment Service
are loosely coupled.
2. Both need to be tested
without any dependencies.
3. Payment Service is an
External Service, So a Mock
Server is required to do the
integration Testing.
@arafkarsh arafkarsh
WireMock – Setup
63
1. WireMock Mock
Payment Server is setup.
2. Payment Service is
initialized with Payment
Gateway (Pointing to
Mock HTTP Server).
3. Step 2 is required if
SpringBootTest is Not
used.
@arafkarsh arafkarsh
WireMock – Payment Accepted
64
@arafkarsh arafkarsh
WireMock – Payment Declined
65
@arafkarsh arafkarsh
WireMock with SpringBootTest
Actual Payment Service &
Config Implementation is
loaded
66
@arafkarsh arafkarsh
PACT
o Consumer Driven Contracts
o Provider Verification
o Pact Broker
o Comparison Mockito / WireMock / Pact
67
@arafkarsh arafkarsh
Use Case – Product and Product Review Service
68
Worker
Nodes
Product Pod
Product Pod
Product Pod
Product
Service
N4
N3
MySQL
DB
EndPoints
N2
Review Pod
Review Pod
Review Pod
Review
Service
N4
N3
N1
Service Call
Kube DNS
EndPoints
Mongo
DB
1. Product and Product
Reviews are two
Microservices getting
developed independently.
2. Both need to be tested
without any dependencies.
3. Contract is driven by
Product Service (Consumer
of Product Review).
@arafkarsh arafkarsh
E2E Testing Vs. Integration Testing
69
Product
Service
Mock
Provider
Review
Service
Review
Service
Mock
Consumer
Product
Service
Break the Test into 2 independently testable units.
Product
Service
Review
Service
End 2 End Testing
is Time Consuming
and Error Prone
@arafkarsh arafkarsh
PACT Architecture – Consumer Testing
70
Product
Service
Mock
Provider
Expected Request
Minimal Response
Interaction
• Pact = A contract between
Consumer and Provider
• Each Pact is a collection of
interactions
Compare
Reply
Expected Request
Minimal Response
Interaction
Provider State
Pact – Contract between
Consumer & Provider
Once the Consumer Testing
is done Pact file is generated
by Pact Framework
Pact Broker
Publish Pacts to
Pact Broker
pact-broker publish --consumer-app-version 1.0.0 --broker-base-url https://broker.com
--broker-token SomeToken /path/to/pacts/consumer-provider.json --tag master
$>
@arafkarsh arafkarsh
PACT Architecture – Provider Testing
71
Review
Service
Mock
Consumer
Expected Request
Minimal Response
Interaction
Provider State
Compare
Send
Once the Consumer
Testing is done Pact
file is generated by
Pact Framework Expected Request
Minimal Response
Interaction
Provider State
Pact – Contract between
Consumer & Provider
@arafkarsh arafkarsh
Pact Definition
Provider Name
Consumer Name
Contract Definition
• @PactTestFor : Provider
• @Pact : Consumer
• Building Request /
Response Pact
72
@arafkarsh arafkarsh
Pact Definition
Consumer Name
Contract Definition
• @PactTestFor : Provider
• @Pact : Consumer
• Building Request /
Response Pact
• Running Consumer Pact
Test
73
@arafkarsh arafkarsh
Pact Contract JSON
1. Contract Defines the
Provider and Consumer
2. N number of Interactions
can be defined under a
single Contract
3. Interaction Defines
Request, Response,
Provider States, Rules etc.
4. Pact Specs v3.0
74
@arafkarsh arafkarsh
Pact : When to use?
75
 Development of Consumer / Provider is
controlled by your team/department/org.
 No. of Consumers are small for a given
Provider
 Consumer and Provider are under active
development.
 Consumer Driven Contract – Provider
features are driven by Consumer.
 Provider team can easily control the data
in the response.
Pact is Good for When
Source: https://docs.pact.io/getting_started/what_is_pact_good_for
 Both teams (Consumer & Provider)
don’t use Pact.
 When the Consumers can’t be
identified (Public APIs)
 Functional / Behavior Testing of the
Provider
 Functionality is Driven by the
Provider.
 Performance and Load Testing
 You can’t control the Response Data.
Pact is NOT Good When
@arafkarsh arafkarsh
Comparison – Mockito / Pact
# Feature Mockito WireMock Pact
TEST SCOPE >>> API Wire Inter Service
1 Contract Testing Yes Yes Yes
2 Behavior / Functional Testing Yes
3 Test Double (Mock Provider) Yes
4
Consumer / Provider Testing using Shared
Contract
Yes
5 Mock System (For Consumer / Provider) Yes Yes
6 Multi Protocol Support (HTTP, Messaging) HTTP Yes
7 Centralized Contract Management Yes
8 API Documentation and Version Management Yes
9 Record and Playback Yes Yes
10 Supports JSON/XML Yes Yes
76
@arafkarsh arafkarsh
Microservices Testing Scenarios / Tools
77
Testing Tools
Contract Testing Scope
Integration Testing
Verifies the communication
paths and interactions between
components to detect interface
defects
Contract Testing
It is a test at the boundary of an
external service verifying that it
meets the contract expected by a
consuming service.
Payment Mock
Integration
Contract
Testing
Scope
Test Double
Montebank
Cart
Component Testing
Unit
Testing
Integration
Testing
Scope
Order
REST / HTTP or
Events / Kafka
Item ID,
Quantity,
Address..
Mock Order
Component Testing
A component test limits the
scope of the exercised
software to a portion of the
system under test.
Order
Payment
Unit
Testing
Firewall
Integration Testing Scope
REST / HTTP
Payment
Sandbox
Component
Testing
U
@arafkarsh arafkarsh
Microservices Testing Strategies
78
E2E
Testing
Integration
Testing
Contract Testing
Component Testing
Unit Testing
Number of Tests
Speed
Cost
Time
Mike Cohen’s Testing Pyramid
Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html
75%
25%
0%
Ubiquitous
Language
Domain
Expert
Analyst Developers
QA
Design
Docs
Test Cases
Code
Architect
@arafkarsh arafkarsh
Chaos Engineering – Load / Stress / Performance
79
Chaos Monkey Randomly disables production instances
Chaos Kong
Similar to Chaos Monkey, simulates an outage of an
entire Amazon availability zone.
Doctor Monkey
Checks CPU load, Memory usage and removes it
from network if the health is bad.
Janitor Monkey Search for unused resources and disposes them.
Compliance Monkey
Finds instances that don’t adhere to best-practices
and shuts them down.
Latency Money Induces Artificial delays
Security Monkey
Is an extension of Compliance Monkey. Find security
vulnerabilities and terminates offending instances.
Source: https://github.com/Netflix/SimianArmy/wiki
Source: http://principlesofchaos.org/
@arafkarsh arafkarsh
Testing Strategy Summary
80
1. Unit Testing
A unit test exercises the smallest piece of testable software.
2. Component Testing
A component test limits the scope of the exercised software to a portion of the system
under test.
3. Contract Testing
It is a test at the boundary of an external service verifying that it meets the contract
expected by a consuming service
4. Integration Testing
It verifies the communication paths and interactions between components to detect
interface defects.
@arafkarsh arafkarsh 81
100s Microservices
1,000s Releases / Day
10,000s Virtual Machines
100K+ User actions / Second
81 M Customers Globally
1 B Time series Metrics
10 B Hours of video streaming
every quarter
Source: NetFlix: : https://www.youtube.com/watch?v=UTKIT6STSVM
10s OPs Engineers
0 NOC
0 Data Centers
So what do NetFlix think about DevOps?
No DevOps
Don’t do lot of Process / Procedures
Freedom for Developers & be Accountable
Trust people you Hire
No Controls / Silos / Walls / Fences
Ownership – You Build it, You Run it.
@arafkarsh arafkarsh 82
Design Patterns are
solutions to general
problems that
software developers
faced during software
development.
Design Patterns
@arafkarsh arafkarsh 83
DREAM | AUTOMATE | EMPOWER
Araf Karsh Hamid :
India: +91.999.545.8627
http://www.slideshare.net/arafkarsh
https://www.linkedin.com/in/arafkarsh/
https://www.youtube.com/user/arafkarsh/playlists
http://www.arafkarsh.com/
@arafkarsh
arafkarsh
@arafkarsh arafkarsh 84
Source Code: https://github.com/MetaArivu Web Site: https://metarivu.com/ https://pyxida.cloud/
@arafkarsh arafkarsh 85
http://www.slideshare.net/arafkarsh
@arafkarsh arafkarsh
References
1. July 15, 2015 – Agile is Dead : GoTo 2015 By Dave Thomas
2. Apr 7, 2016 - Agile Project Management with Kanban | Eric Brechner | Talks at Google
3. Sep 27, 2017 - Scrum vs Kanban - Two Agile Teams Go Head-to-Head
4. Feb 17, 2019 - Lean vs Agile vs Design Thinking
5. Dec 17, 2020 - Scrum vs Kanban | Differences & Similarities Between Scrum & Kanban
6. Feb 24, 2021 - Agile Methodology Tutorial for Beginners | Jira Tutorial | Agile Methodology Explained.
Agile Methodologies
86
@arafkarsh arafkarsh
References
1. Vmware: What is Cloud Architecture?
2. Redhat: What is Cloud Architecture?
3. Cloud Computing Architecture
4. Cloud Adoption Essentials:
5. Google: Hybrid and Multi Cloud
6. IBM: Hybrid Cloud Architecture Intro
7. IBM: Hybrid Cloud Architecture: Part 1
8. IBM: Hybrid Cloud Architecture: Part 2
9. Cloud Computing Basics: IaaS, PaaS, SaaS
87
1. IBM: IaaS Explained
2. IBM: PaaS Explained
3. IBM: SaaS Explained
4. IBM: FaaS Explained
5. IBM: What is Hypervisor?
Cloud Architecture
@arafkarsh arafkarsh
References
Microservices
1. Microservices Definition by Martin Fowler
2. When to use Microservices By Martin Fowler
3. GoTo: Sep 3, 2020: When to use Microservices By Martin Fowler
4. GoTo: Feb 26, 2020: Monolith Decomposition Pattern
5. Thought Works: Microservices in a Nutshell
6. Microservices Prerequisites
7. What do you mean by Event Driven?
8. Understanding Event Driven Design Patterns for Microservices
88
@arafkarsh arafkarsh
References – Microservices – Videos
89
1. Martin Fowler – Micro Services : https://www.youtube.com/watch?v=2yko4TbC8cI&feature=youtu.be&t=15m53s
2. GOTO 2016 – Microservices at NetFlix Scale: Principles, Tradeoffs & Lessons Learned. By R Meshenberg
3. Mastering Chaos – A NetFlix Guide to Microservices. By Josh Evans
4. GOTO 2015 – Challenges Implementing Micro Services By Fred George
5. GOTO 2016 – From Monolith to Microservices at Zalando. By Rodrigue Scaefer
6. GOTO 2015 – Microservices @ Spotify. By Kevin Goldsmith
7. Modelling Microservices @ Spotify : https://www.youtube.com/watch?v=7XDA044tl8k
8. GOTO 2015 – DDD & Microservices: At last, Some Boundaries By Eric Evans
9. GOTO 2016 – What I wish I had known before Scaling Uber to 1000 Services. By Matt Ranney
10. DDD Europe – Tackling Complexity in the Heart of Software By Eric Evans, April 11, 2016
11. AWS re:Invent 2016 – From Monolithic to Microservices: Evolving Architecture Patterns. By Emerson L, Gilt D. Chiles
12. AWS 2017 – An overview of designing Microservices based Applications on AWS. By Peter Dalbhanjan
13. GOTO Jun, 2017 – Effective Microservices in a Data Centric World. By Randy Shoup.
14. GOTO July, 2017 – The Seven (more) Deadly Sins of Microservices. By Daniel Bryant
15. Sept, 2017 – Airbnb, From Monolith to Microservices: How to scale your Architecture. By Melanie Cubula
16. GOTO Sept, 2017 – Rethinking Microservices with Stateful Streams. By Ben Stopford.
17. GOTO 2017 – Microservices without Servers. By Glynn Bird.
@arafkarsh arafkarsh
References
90
Domain Driven Design
1. Oct 27, 2012 What I have learned about DDD Since the book. By Eric Evans
2. Mar 19, 2013 Domain Driven Design By Eric Evans
3. Jun 02, 2015 Applied DDD in Java EE 7 and Open Source World
4. Aug 23, 2016 Domain Driven Design the Good Parts By Jimmy Bogard
5. Sep 22, 2016 GOTO 2015 – DDD & REST Domain Driven API’s for the Web. By Oliver Gierke
6. Jan 24, 2017 Spring Developer – Developing Micro Services with Aggregates. By Chris Richardson
7. May 17. 2017 DEVOXX – The Art of Discovering Bounded Contexts. By Nick Tune
8. Dec 21, 2019 What is DDD - Eric Evans - DDD Europe 2019. By Eric Evans
9. Oct 2, 2020 - Bounded Contexts - Eric Evans - DDD Europe 2020. By. Eric Evans
10. Oct 2, 2020 - DDD By Example - Paul Rayner - DDD Europe 2020. By Paul Rayner
@arafkarsh arafkarsh
References
Event Sourcing and CQRS
1. IBM: Event Driven Architecture – Mar 21, 2021
2. Martin Fowler: Event Driven Architecture – GOTO 2017
3. Greg Young: A Decade of DDD, Event Sourcing & CQRS – April 11, 2016
4. Nov 13, 2014 GOTO 2014 – Event Sourcing. By Greg Young
5. Mar 22, 2016 Building Micro Services with Event Sourcing and CQRS
6. Apr 15, 2016 YOW! Nights – Event Sourcing. By Martin Fowler
7. May 08, 2017 When Micro Services Meet Event Sourcing. By Vinicius Gomes
91
@arafkarsh arafkarsh
References
92
Kafka
1. Understanding Kafka
2. Understanding RabbitMQ
3. IBM: Apache Kafka – Sept 18, 2020
4. Confluent: Apache Kafka Fundamentals – April 25, 2020
5. Confluent: How Kafka Works – Aug 25, 2020
6. Confluent: How to integrate Kafka into your environment – Aug 25, 2020
7. Kafka Streams – Sept 4, 2021
8. Kafka: Processing Streaming Data with KSQL – Jul 16, 2018
9. Kafka: Processing Streaming Data with KSQL – Nov 28, 2019
@arafkarsh arafkarsh
References
Databases: Big Data / Cloud Databases
1. Google: How to Choose the right database?
2. AWS: Choosing the right Database
3. IBM: NoSQL Vs. SQL
4. A Guide to NoSQL Databases
5. How does NoSQL Databases Work?
6. What is Better? SQL or NoSQL?
7. What is DBaaS?
8. NoSQL Concepts
9. Key Value Databases
10. Document Databases
11. Jun 29, 2012 – Google I/O 2012 - SQL vs NoSQL: Battle of the Backends
12. Feb 19, 2013 - Introduction to NoSQL • Martin Fowler • GOTO 2012
13. Jul 25, 2018 - SQL vs NoSQL or MySQL vs MongoDB
14. Oct 30, 2020 - Column vs Row Oriented Databases Explained
15. Dec 9, 2020 - How do NoSQL databases work? Simply Explained!
1. Graph Databases
2. Column Databases
3. Row Vs. Column Oriented Databases
4. Database Indexing Explained
5. MongoDB Indexing
6. AWS: DynamoDB Global Indexing
7. AWS: DynamoDB Local Indexing
8. Google Cloud Spanner
9. AWS: DynamoDB Design Patterns
10. Cloud Provider Database Comparisons
11. CockroachDB: When to use a Cloud DB?
93
@arafkarsh arafkarsh
References
Docker / Kubernetes / Istio
1. IBM: Virtual Machines and Containers
2. IBM: What is a Hypervisor?
3. IBM: Docker Vs. Kubernetes
4. IBM: Containerization Explained
5. IBM: Kubernetes Explained
6. IBM: Kubernetes Ingress in 5 Minutes
7. Microsoft: How Service Mesh works in Kubernetes
8. IBM: Istio Service Mesh Explained
9. IBM: Kubernetes and OpenShift
10. IBM: Kubernetes Operators
11. 10 Consideration for Kubernetes Deployments
Istio – Metrics
1. Istio – Metrics
2. Monitoring Istio Mesh with Grafana
3. Visualize your Istio Service Mesh
4. Security and Monitoring with Istio
5. Observing Services using Prometheus, Grafana, Kiali
6. Istio Cookbook: Kiali Recipe
7. Kubernetes: Open Telemetry
8. Open Telemetry
9. How Prometheus works
10. IBM: Observability vs. Monitoring
94
@arafkarsh arafkarsh
References
95
1. Feb 6, 2020 – An introduction to TDD
2. Aug 14, 2019 – Component Software Testing
3. May 30, 2020 – What is Component Testing?
4. Apr 23, 2013 – Component Test By Martin Fowler
5. Jan 12, 2011 – Contract Testing By Martin Fowler
6. Jan 16, 2018 – Integration Testing By Martin Fowler
7. Testing Strategies in Microservices Architecture
8. Practical Test Pyramid By Ham Vocke
Testing – TDD / BDD
@arafkarsh arafkarsh 96
1. Simoorg : LinkedIn’s own failure inducer framework. It was designed to be easy to extend and
most of the important components are plug‐ gable.
2. Pumba : A chaos testing and network emulation tool for Docker.
3. Chaos Lemur : Self-hostable application to randomly destroy virtual machines in a BOSH-
managed environment, as an aid to resilience testing of high-availability systems.
4. Chaos Lambda : Randomly terminate AWS ASG instances during business hours.
5. Blockade : Docker-based utility for testing network failures and partitions in distributed
applications.
6. Chaos-http-proxy : Introduces failures into HTTP requests via a proxy server.
7. Monkey-ops : Monkey-Ops is a simple service implemented in Go, which is deployed into an
OpenShift V3.X and generates some chaos within it. Monkey-Ops seeks some OpenShift
components like Pods or Deployment Configs and randomly terminates them.
8. Chaos Dingo : Chaos Dingo currently supports performing operations on Azure VMs and VMSS
deployed to an Azure Resource Manager-based resource group.
9. Tugbot : Testing in Production (TiP) framework for Docker.
Testing tools
@arafkarsh arafkarsh
References
CI / CD
1. What is Continuous Integration?
2. What is Continuous Delivery?
3. CI / CD Pipeline
4. What is CI / CD Pipeline?
5. CI / CD Explained
6. CI / CD Pipeline using Java Example Part 1
7. CI / CD Pipeline using Ansible Part 2
8. Declarative Pipeline vs Scripted Pipeline
9. Complete Jenkins Pipeline Tutorial
10. Common Pipeline Mistakes
11. CI / CD for a Docker Application
97
@arafkarsh arafkarsh
References
98
DevOps
1. IBM: What is DevOps?
2. IBM: Cloud Native DevOps Explained
3. IBM: Application Transformation
4. IBM: Virtualization Explained
5. What is DevOps? Easy Way
6. DevOps?! How to become a DevOps Engineer???
7. Amazon: https://www.youtube.com/watch?v=mBU3AJ3j1rg
8. NetFlix: https://www.youtube.com/watch?v=UTKIT6STSVM
9. DevOps and SRE: https://www.youtube.com/watch?v=uTEL8Ff1Zvk
10. SLI, SLO, SLA : https://www.youtube.com/watch?v=tEylFyxbDLE
11. DevOps and SRE : Risks and Budgets : https://www.youtube.com/watch?v=y2ILKr8kCJU
12. SRE @ Google: https://www.youtube.com/watch?v=d2wn_E1jxn4
@arafkarsh arafkarsh
References
99
1. Lewis, James, and Martin Fowler. “Microservices: A Definition of This New Architectural Term”, March 25, 2014.
2. Miller, Matt. “Innovate or Die: The Rise of Microservices”. e Wall Street Journal, October 5, 2015.
3. Newman, Sam. Building Microservices. O’Reilly Media, 2015.
4. Alagarasan, Vijay. “Seven Microservices Anti-patterns”, August 24, 2015.
5. Cockcroft, Adrian. “State of the Art in Microservices”, December 4, 2014.
6. Fowler, Martin. “Microservice Prerequisites”, August 28, 2014.
7. Fowler, Martin. “Microservice Tradeoffs”, July 1, 2015.
8. Humble, Jez. “Four Principles of Low-Risk Software Release”, February 16, 2012.
9. Zuul Edge Server, Ketan Gote, May 22, 2017
10. Ribbon, Hysterix using Spring Feign, Ketan Gote, May 22, 2017
11. Eureka Server with Spring Cloud, Ketan Gote, May 22, 2017
12. Apache Kafka, A Distributed Streaming Platform, Ketan Gote, May 20, 2017
13. Functional Reactive Programming, Araf Karsh Hamid, August 7, 2016
14. Enterprise Software Architectures, Araf Karsh Hamid, July 30, 2016
15. Docker and Linux Containers, Araf Karsh Hamid, April 28, 2015
@arafkarsh arafkarsh
References
100
16. MSDN – Microsoft https://msdn.microsoft.com/en-us/library/dn568103.aspx
17. Martin Fowler : CQRS – http://martinfowler.com/bliki/CQRS.html
18. Udi Dahan : CQRS – http://www.udidahan.com/2009/12/09/clarified-cqrs/
19. Greg Young : CQRS - https://www.youtube.com/watch?v=JHGkaShoyNs
20. Bertrand Meyer – CQS - http://en.wikipedia.org/wiki/Bertrand_Meyer
21. CQS : http://en.wikipedia.org/wiki/Command–query_separation
22. CAP Theorem : http://en.wikipedia.org/wiki/CAP_theorem
23. CAP Theorem : http://www.julianbrowne.com/article/viewer/brewers-cap-theorem
24. CAP 12 years how the rules have changed
25. EBay Scalability Best Practices : http://www.infoq.com/articles/ebay-scalability-best-practices
26. Pat Helland (Amazon) : Life beyond distributed transactions
27. Stanford University: Rx https://www.youtube.com/watch?v=y9xudo3C1Cw
28. Princeton University: SAGAS (1987) Hector Garcia Molina / Kenneth Salem
29. Rx Observable : https://dzone.com/articles/using-rx-java-observable

More Related Content

What's hot

What's hot (20)

CI-CD Jenkins, GitHub Actions, Tekton
CI-CD Jenkins, GitHub Actions, Tekton CI-CD Jenkins, GitHub Actions, Tekton
CI-CD Jenkins, GitHub Actions, Tekton
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven Design
 
Containers Docker Kind Kubernetes Istio
Containers Docker Kind Kubernetes IstioContainers Docker Kind Kubernetes Istio
Containers Docker Kind Kubernetes Istio
 
Microservices, DevOps & SRE
Microservices, DevOps & SREMicroservices, DevOps & SRE
Microservices, DevOps & SRE
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
Build CICD Pipeline for Container Presentation Slides
Build CICD Pipeline for Container Presentation SlidesBuild CICD Pipeline for Container Presentation Slides
Build CICD Pipeline for Container Presentation Slides
 
How we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on KubernetesHow we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on Kubernetes
 
Azure dev ops
Azure dev opsAzure dev ops
Azure dev ops
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
DevSecOps 101
DevSecOps 101DevSecOps 101
DevSecOps 101
 
Azure kubernetes service (aks)
Azure kubernetes service (aks)Azure kubernetes service (aks)
Azure kubernetes service (aks)
 
Why Microservice
Why Microservice Why Microservice
Why Microservice
 
DEVSECOPS.pptx
DEVSECOPS.pptxDEVSECOPS.pptx
DEVSECOPS.pptx
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SRE
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Circuit Breaker Pattern
Circuit Breaker PatternCircuit Breaker Pattern
Circuit Breaker Pattern
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 
Introduction to DevSecOps
Introduction to DevSecOpsIntroduction to DevSecOps
Introduction to DevSecOps
 
Introduction to Azure Functions
Introduction to Azure FunctionsIntroduction to Azure Functions
Introduction to Azure Functions
 

Similar to Microservices Testing Strategies JUnit Cucumber Mockito Pact

Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
Ramu Palanki
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
Ramu Palanki
 

Similar to Microservices Testing Strategies JUnit Cucumber Mockito Pact (20)

Service Mesh - Observability
Service Mesh - ObservabilityService Mesh - Observability
Service Mesh - Observability
 
Micro frontend: The microservices puzzle extended to frontend
Micro frontend: The microservices puzzle  extended to frontendMicro frontend: The microservices puzzle  extended to frontend
Micro frontend: The microservices puzzle extended to frontend
 
#ATAGTR2019 Presentation "Top 10 quality engineering best practices to achiev...
#ATAGTR2019 Presentation "Top 10 quality engineering best practices to achiev...#ATAGTR2019 Presentation "Top 10 quality engineering best practices to achiev...
#ATAGTR2019 Presentation "Top 10 quality engineering best practices to achiev...
 
Eradicate Flaky Tests
Eradicate Flaky TestsEradicate Flaky Tests
Eradicate Flaky Tests
 
About Qtp 92
About Qtp 92About Qtp 92
About Qtp 92
 
About QTP 9.2
About QTP 9.2About QTP 9.2
About QTP 9.2
 
About Qtp_1 92
About Qtp_1 92About Qtp_1 92
About Qtp_1 92
 
Shuvam dutta
Shuvam duttaShuvam dutta
Shuvam dutta
 
Shuvam dutta | Performance tester
Shuvam dutta | Performance testerShuvam dutta | Performance tester
Shuvam dutta | Performance tester
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearch
 
Testing APEX apps At A Glance
Testing APEX apps At A GlanceTesting APEX apps At A Glance
Testing APEX apps At A Glance
 
Just Enough (Automated) Testing
Just Enough (Automated) TestingJust Enough (Automated) Testing
Just Enough (Automated) Testing
 
Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Gowtham_resume
Gowtham_resumeGowtham_resume
Gowtham_resume
 
Shruti Kulkarni (1)
Shruti Kulkarni (1)Shruti Kulkarni (1)
Shruti Kulkarni (1)
 
26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team
 
Eradicate Flaky Tests - AppiumConf 2021
Eradicate Flaky Tests - AppiumConf 2021Eradicate Flaky Tests - AppiumConf 2021
Eradicate Flaky Tests - AppiumConf 2021
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platform
 

More from Araf Karsh Hamid

More from Araf Karsh Hamid (16)

Cloud Architecture - Multi Cloud, Edge, On-Premise
Cloud Architecture - Multi Cloud, Edge, On-PremiseCloud Architecture - Multi Cloud, Edge, On-Premise
Cloud Architecture - Multi Cloud, Edge, On-Premise
 
Microservices Architecture, Monolith Migration Patterns
Microservices Architecture, Monolith Migration PatternsMicroservices Architecture, Monolith Migration Patterns
Microservices Architecture, Monolith Migration Patterns
 
Apache Flink, AWS Kinesis, Analytics
Apache Flink, AWS Kinesis, Analytics Apache Flink, AWS Kinesis, Analytics
Apache Flink, AWS Kinesis, Analytics
 
Microservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native AppsMicroservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native Apps
 
Domain Driven Design
Domain Driven Design Domain Driven Design
Domain Driven Design
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
 
Blockchain HyperLedger Fabric Internals - Clavent
Blockchain HyperLedger Fabric Internals - ClaventBlockchain HyperLedger Fabric Internals - Clavent
Blockchain HyperLedger Fabric Internals - Clavent
 
Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric
 
Docker Kubernetes Istio
Docker Kubernetes IstioDocker Kubernetes Istio
Docker Kubernetes Istio
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
Blockchain Hyper Ledger Fabric : Bangkok Conference
Blockchain Hyper Ledger Fabric : Bangkok ConferenceBlockchain Hyper Ledger Fabric : Bangkok Conference
Blockchain Hyper Ledger Fabric : Bangkok Conference
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger Fabric
 
Event Storming and Saga
Event Storming and SagaEvent Storming and Saga
Event Storming and Saga
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Microservices Testing Strategies JUnit Cucumber Mockito Pact

  • 1. @arafkarsh arafkarsh ARAF KARSH HAMID Co-Founder / CTO MetaMagic Global Inc., NJ, USA @arafkarsh arafkarsh 1 Microservices Architecture Series Building Cloud Native Apps Testing Strategies Behavior Driven Design JUnit 5, Cucumber, Selenium, Mockito, WireMock, Pact Part 6 of 11
  • 2. @arafkarsh arafkarsh 2 Slides are color coded based on the topic colors. Microservices Testing Strategies 1 Unit Testing JUnit 5 2 Behavior Driven Development Cucumber, Selenium Mockito 3 Integration / Contract Testing WireMock, Pact 4
  • 3. @arafkarsh arafkarsh Agile Scrum (4-6 Weeks) Developer Journey Monolithic Domain Driven Design Event Sourcing and CQRS Waterfall Optional Design Patterns Continuous Integration (CI) 6/12 Months Enterprise Service Bus Relational Database [SQL] / NoSQL Development QA / QC Ops 3 Microservices Domain Driven Design Event Sourcing and CQRS Scrum / Kanban (1-5 Days) Mandatory Design Patterns Infrastructure Design Patterns CI DevOps Event Streaming / Replicated Logs SQL NoSQL CD Container Orchestrator Service Mesh
  • 4. @arafkarsh arafkarsh Microservices Testing Strategies • Unit testing • Component testing • Integration Contract testing • Integration testing 4 1
  • 5. @arafkarsh arafkarsh Microservices Testing Strategies 5 E2E Testing Integration Testing Contract Testing Component Testing Unit Testing Number of Tests Speed Cost Time Mike Cohen’s Testing Pyramid Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html 70% 20% 10% Ubiquitous Language Domain Expert Analyst Developers QA Design Docs Test Cases Code Architect
  • 6. @arafkarsh arafkarsh Other Testing Strategies or Anti Patterns 6 Inverted Pyramid / Ice Cream Cone Strategy Unit Testing Integration Testing End 2 End Testing Hour Glass Strategy 70% 20% 10% 45% 45% 10%
  • 7. @arafkarsh arafkarsh Microservices Testing Strategy 7 Unit Testing A unit test exercises the smallest piece of testable software in the application to determine whether it behaves as expected. Source: https://martinfowler.com/articles/microservice-testing/#agenda Component Testing A component test limits the scope of the exercised software to a portion of the system under test, manipulating the system through internal code interfaces and using test doubles to isolate the code under test from other components. Integration Testing An integration test verifies the communication paths and interactions between components to detect interface defects Integration Contract Testing An Integration Contract test is a test at the boundary of an external service verifying that it meets the contract expected by a consuming service. End 2 End Testing An end-to-end test verifies that a system meets external requirements and achieves its goals, testing the entire system, from end to end Say NO to End 2 End Tests - Mike Walker April 22, 2015. Google Test Blog
  • 8. @arafkarsh arafkarsh Microservices Testing Scenarios / Tools 8 Testing Tools Contract Testing Scope Integration Testing Verifies the communication paths and interactions between components to detect interface defects Contract Testing It is a test at the boundary of an external service verifying that it meets the contract expected by a consuming service. Payment Mock Integration Contract Testing Scope Test Double Montebank Cart Component Testing Unit Testing Integration Testing Scope Order REST / HTTP or Events / Kafka Item ID, Quantity, Address.. Mock Order Component Testing A component test limits the scope of the exercised software to a portion of the system under test. Order Payment Unit Testing Firewall Integration Testing Scope REST / HTTP Payment Sandbox Component Testing U
  • 10. @arafkarsh arafkarsh Package Structure 10 1. Order Service 2. Payment Service 3. Packing Service 4. Shipping Service 5. Warehouse Service 6. Delivery City Service Services 1. Order Controller Controllers Source: https://github.com/MetaArivu/ms-order-service
  • 11. @arafkarsh arafkarsh Order Service API Calls 11 http://localhost:90880/swagger-ui.html Based on Open API v3
  • 12. @arafkarsh arafkarsh JUnit 5 • JUnit 5 Testing • Annotations • Tags and Filtering • Meta Annotations • Basic Assertions in JUnit 5 • Testing Categories 12 2
  • 13. @arafkarsh arafkarsh JUnit 5 – Unit Testing 13 Assert @BeforeAll @BeforeEach @Test @AfterEach @AfterAll System Under Test All the Test Cases Setup Check Verify Teardown Test Suites Teardown All Setup All
  • 14. @arafkarsh arafkarsh JUnit 5 – Test Annotations 14 @Test @RepeatedTest @ParametrizedTest @NestedTest @ValueSource @EnumSource @MethodSource @CsvSource @CsvFileSource @ArgumentSource @DisplayName Give meaningful name for your tests @Tag Categorize and Filter your tests. @Order Execute your tests in a specific order. @Disabled Disables your test
  • 15. @arafkarsh arafkarsh JUnit 5 – Tags and Filtering 15 Functional Non-Functional Performance Usability Security Accessibility Stress Load
  • 16. @arafkarsh arafkarsh JUnit 5 – Meta Annotations 16 Non-Functional Performance Load
  • 17. @arafkarsh arafkarsh Filtering in POM File using Sure Fire Plugin 1. Using Tags, you can filter specific tests to get executed in your build process. 2. For Ex. If you tags like All, Unit, Components, Contract, and Integration and you want to run only Component and Contract Testing and exclude Non- Functional Tests. Then <groups> Component, Contract </groups> <excludedGroups> Non-Functional </excludedGroups>
  • 18. @arafkarsh arafkarsh Basic Assertions in JUnit 5 18 Assertion Details fail Fails a test with a given message and or Exception assertTrue Validates that the supplied Condition is True assertFalse Validates that the supplied Condition is False assertNull Validates the the supplied Object is Null assertEquals Validates that 2 supplied Objects are equal assertArrayEquals Validates that 2 supplied Arrays are equals assertIterableEquals Validates that 2 supplied Iterable Objects are equal. assertLineMatch Validates that 2 lines of Strings are equal. assertNotEquals Validates that 2 supplied Objects are NOT Equal assertSame Validates that 2 Object are same – compared with == assertNotSame Validates that 2 Objects are not same – compared with !=
  • 19. @arafkarsh arafkarsh Assertions in JUnit 5 19 Assertion Details assertAll Groups different Assertion at the same time assertThrows To verify that a given Exception is thrown from piece of code. assertTimeout Verifies the timeout of a given operation assertTimeoutPreemptively If the timeout exceeds then terminated. 3rd Party Assertions assertThat An object is matched with a Matcher to see if it meets the expectation.
  • 20. @arafkarsh arafkarsh JUnit 4 >> JUnit 5 20 JUnit 4 JUnit 5 @BeforeClass Executed Before All @Test in the Current Class @BeforeAll @Before Executed Before each @Test @BeforeEach @After Executed After Each @Test @AfterEach @AfterClass Executed After All @Test in the Current Class @AfterAll @Category To Group the test cases @Tag
  • 21. @arafkarsh arafkarsh Junit 5 – Parametrized Tests 21 Value Source Enum Source
  • 22. @arafkarsh arafkarsh JUnit 5 – Parametrized Tests 22 CSV Source CSV File Source
  • 23. @arafkarsh arafkarsh JUnit 5 – Parametrized Tests 23 Method Source
  • 24. @arafkarsh arafkarsh JUnit 5 – Parametrized Tests 24 Argument Source Argument Source Provider
  • 25. @arafkarsh arafkarsh JUnit 5 – Nested Tests 25
  • 26. @arafkarsh arafkarsh JUnit 5 – Repeated Tests 26
  • 28. @arafkarsh arafkarsh Features of BDD 28 • Focus on Behavior of the System rather than tests. • Collaboration between Business Stake holders, Analysts, Developers, QA. • Ubiquitous Language • Driven By Business Value • Extends Test Driven Development https://cucumber.io/ Free and Open-Source Framework for Java Stack. Free and Open Source BDD Framework for .Net Stack https://specflow.org/
  • 29. @arafkarsh arafkarsh Behavior Driven Development 29 Source: https://dannorth.net/introducing-bdd/ As an insurance Broker I want to know who my Gold Customers are So that I sell more Given Customer John Doe exists When he buys insurance ABC for $1000 USD Then He becomes a Gold Customer BDD Construct Role-Feature-Reason Matrix As a Customer I want to withdraw Cash from ATM So that I don’t have to wait in line at the bank Given The account is in Credit AND the Card is Valid AND the dispenser contains Cash BDD Construct Role-Feature-Reason Matrix When The Customer requests Cash Then Ensure that the Account is debited AND Ensure cash is dispensed AND ensure that Card is returned.
  • 30. @arafkarsh arafkarsh Theme/Epic – Shopping Portal / Cart 30 As a Consumer I want to Add a Product to Cart So that I can buy the product Role-Feature-Reason Matrix User Story – 1 : Add to Cart BDD Acceptance Criteria – 1: Add to Cart Given The user logged into the portal and a Product is selected and Product details are available When The user then clicks Add to Cart Button Then The system will add the Item (Product) into the card and Updates Item counter in the Cart Icon AND Saves the Cart information in the DB AND if the save fails the system shows an Error “Unable to Add Product to the Cart”. BDD Acceptance Criteria – 2: Save Cart Given The Request is authenticated When The Input contains user login id, product id Then The system will add the Item (Product) into the Cart & Saves the Cart information in the DB AND if the save fails the system shows an Error “Unable to Add Product to the Cart”.
  • 31. @arafkarsh arafkarsh Theme/Epic – Shopping Portal / Customer 31 As a Consumer I want to Select Shipping Address So that I can ship the items to that Address Role-Feature-Reason Matrix User Story – 3 : Select Address BDD Acceptance Criteria – 1 : Show Address Given The user in the Shopping Cart Page When User Clicks Proceed to Buy Button Then The System shows the Available Address for Shipping BDD Acceptance Criteria – 2 : Select Address Given The user in the Shopping Cart Page with Available Shipping Address When User Selects Address and Clicks Proceed to Buy Then The System save the Temp Order details from Items from Shopping and Selected Shipping Address AND this details are valid only for the user session. If the order is not placed Temp Order items will be put back in Cart DB BDD Acceptance Criteria – 3 : Save Temp Order Given The Request is authenticated When Input contains user login id, items, shipping address Then The System save the Temp Order details from Items from Shopping and Selected Shipping Address AND this details are valid only for the user session. If the order is not placed Temp Order items will be put back in Cart DB
  • 32. @arafkarsh arafkarsh Theme/Epic – Shopping Portal / Order 32 As a Consumer I want to Process the Order So that I can buy products Role-Feature-Reason Matrix User Story – 1 : Process Order BDD Acceptance Criteria – 1 : Add Payment Given The user in the Order Cart Page with Items and selected Shipping Address When User Selects Payment Option As Credit Card AND Input the Credit Card Details in the following fields Card Name, Card No. Expiry Date, CVV Number Then The System Validates the Credit Card Number and the Expiry Date and Card Name & CVV Must NOT be Null IF Invalid Systems says invalid Payment details else Saves the info and proceed for payment. BDD Acceptance Criteria – 3 : Save Payment Given The Request is authenticated When Input contains user login id, order id, payment details (card number only last 4 digits) Then The System Validates the Credit Card Number and the Expiry Date and Card Name and CVV Must NOT be Null IF Invalid Systems returns invalid Payment details ELSE Saves the following info Card Name, Card Number (only last 4 digits), Expiry Date BDD Acceptance Criteria – 3 : Payment Gateway Given The Request is authenticated When Input contains Valid payment details Then With the Valid Payment Details System calls External Payment Service for Payment Processing and Returns Result to Calling System
  • 33. @arafkarsh arafkarsh As a Patient I want to get diagnosed by a Doctor So that I can be healthy again Role-Feature-Reason Matrix User Story – 1 : Patient Diagnosis BDD Acceptance Criteria – 1 : Show Patient Info Given The Patient John Doe Exists and has an Appointment with the doctor When The Doctor selects the Patient Info Then The System shows the Patient Info with following details Patient Name, Age, Gender, Contact No. and the Health info contains the following Pulse, Blood Pressure, Height and Weight BDD Acceptance Criteria – 2 : Add Diagnosis Given Patient Details are Available When Doctor Selects Add Diagnosis Then The system shows a text area for adding the diagnosis and the doctor can add multiple diagnosis. BDD Acceptance Criteria – 4 : Save Diagnosis Given The Request is authenticated When Input contains Patient Diagnosis Details Then With the Valid Patient Diagnosis Details and the system will save the data send the response back to the user. BDD Acceptance Criteria – 3 : Add Prescription Given Patient Details & Diagnosis are Available When Doctor Selects Add Prescription Then The system shows a text area for adding the prescription, and the frequency of usage in a day and for how many days, and the doctor can add multiple prescription. Theme/Epic – Hospital / Diagnosis 33
  • 34. @arafkarsh arafkarsh BDD Specs 34 BDD Style Specs for Searching for a Product in Amazon
  • 35. @arafkarsh arafkarsh Cucumber JUnit 4 Integration 35 Specs Definition Steps for Testing
  • 37. @arafkarsh arafkarsh Specs for Payment Criteria 37
  • 38. @arafkarsh arafkarsh Cucumber Junit 4 Integration 38 Specs Definition Steps for Testing
  • 39. @arafkarsh arafkarsh Mockito Component / Mock / Contract Testing 39
  • 40. @arafkarsh arafkarsh Mock Testing Tools Trends for Last 5 Years 40
  • 41. @arafkarsh arafkarsh Mockito Concepts 41 Verify 3. Verify Expectations and Results Verify Result 1. Set the expectations Expect When() Then Return() Use 2. Use the object being tested Test your Component
  • 42. @arafkarsh arafkarsh Annotation – @Mock, @InjectMock 42 Create Mocks for 1. Repository 2. Payment Service Inject the Mocks into Order Service Scenario Create Mocks for the following 1. Repository Service 2. Payment Service Annotations • @Mock • @InjectMocks Test Cases 1. Given a Valid Order 2. Test for Payment Accepted 3. Test for Payment Declined
  • 43. @arafkarsh arafkarsh Conditions – when().thenReturn() 43 Test Cases 1. Given a Valid Order 2. Test for Payment Accepted 3. Test for Payment Declined
  • 44. @arafkarsh arafkarsh Annotation - @Spy 44 Spy works on the Actual Implementation Inject the Mocks into Order Service Scenario Create Mocks for the following 1. Packaging Service 2. Shipping Service Annotations • @Spy • @Mock • @InjectMocks Test Cases 1. Given a Valid Paid Order 2. Test for Packaging 3. Test for Shipping
  • 45. @arafkarsh arafkarsh Annotation - @Spy 45 Scenario – 1 Create Mocks for the following 1. Packaging Service 2. Shipping Service Annotations • @Spy • @Mock • @InjectMocks Test Cases 1. Given a Valid Paid Order 2. Test for Packaging 3. Test for Shipping
  • 46. @arafkarsh arafkarsh Annotation – @Spy 46 Scenario – 2 Create Mocks for the following 1. Packaging Service 2. Shipping Service Annotations • @Spy • @Mock • @InjectMocks Test Cases 1. Given a Valid Paid Order 2. Test for Packaging 3. Test for Shipping
  • 47. @arafkarsh arafkarsh Annotation – @Spy 47 Scenario – 3 Create Mocks for the following 1. Packaging Service 2. Shipping Service Annotations • @Spy • @Mock • @InjectMocks Test Cases 1. Given a Valid Paid Order 2. Test for Packaging 3. Test for Shipping
  • 48. @arafkarsh arafkarsh Advanced Features 48 Scenario Shipping Service with Delivery City Details for the final Shipment Mockito Advanced Features 1. Ordering the Input – InOrder 2. Argument Matcher 3. Counts 4. Built In Answer 5. Storing Arguments – Captor 6. Throwing Exceptions
  • 50. @arafkarsh arafkarsh Advanced Features – Argument Matcher 50
  • 51. @arafkarsh arafkarsh Advanced Features – Count : External Calls 51
  • 52. @arafkarsh arafkarsh Advanced Features – Built in Answers 52
  • 53. @arafkarsh arafkarsh Advanced Features – Built in Answers 53
  • 54. @arafkarsh arafkarsh Advanced Features – Captor : Argument Capture 54
  • 55. @arafkarsh arafkarsh Advanced Features – Catching Exception 55
  • 57. @arafkarsh arafkarsh Spring Boot Test 1. Getting Application Context 2. Auto wiring the dependencies 3. JUnit 5 Based Examples  This is required for WireMock and Pact Actual Payment Service Implementation is loaded 57
  • 58. @arafkarsh arafkarsh SpringBootTest POM Config for JUnit 5 58 Exclude Default JUnit 4 SBT v 2.5.3
  • 60. @arafkarsh arafkarsh WireMock o Without SpringBootTest o With SpringBootTest 60
  • 61. @arafkarsh arafkarsh WireMock Architecture 61 Service (Client) WireMock Request Mapping Response Data HTTP/S Calls
  • 62. @arafkarsh arafkarsh Use Case – Order and Payment Service 62 Worker Nodes Order Pod Order Pod Order Pod Order Service N4 N3 MySQL DB EndPoints N2 Payment Pod Payment Pod Payment Pod Payment Service Service Call Kube DNS EndPoints 1. Order and Payment Service are loosely coupled. 2. Both need to be tested without any dependencies. 3. Payment Service is an External Service, So a Mock Server is required to do the integration Testing.
  • 63. @arafkarsh arafkarsh WireMock – Setup 63 1. WireMock Mock Payment Server is setup. 2. Payment Service is initialized with Payment Gateway (Pointing to Mock HTTP Server). 3. Step 2 is required if SpringBootTest is Not used.
  • 64. @arafkarsh arafkarsh WireMock – Payment Accepted 64
  • 65. @arafkarsh arafkarsh WireMock – Payment Declined 65
  • 66. @arafkarsh arafkarsh WireMock with SpringBootTest Actual Payment Service & Config Implementation is loaded 66
  • 67. @arafkarsh arafkarsh PACT o Consumer Driven Contracts o Provider Verification o Pact Broker o Comparison Mockito / WireMock / Pact 67
  • 68. @arafkarsh arafkarsh Use Case – Product and Product Review Service 68 Worker Nodes Product Pod Product Pod Product Pod Product Service N4 N3 MySQL DB EndPoints N2 Review Pod Review Pod Review Pod Review Service N4 N3 N1 Service Call Kube DNS EndPoints Mongo DB 1. Product and Product Reviews are two Microservices getting developed independently. 2. Both need to be tested without any dependencies. 3. Contract is driven by Product Service (Consumer of Product Review).
  • 69. @arafkarsh arafkarsh E2E Testing Vs. Integration Testing 69 Product Service Mock Provider Review Service Review Service Mock Consumer Product Service Break the Test into 2 independently testable units. Product Service Review Service End 2 End Testing is Time Consuming and Error Prone
  • 70. @arafkarsh arafkarsh PACT Architecture – Consumer Testing 70 Product Service Mock Provider Expected Request Minimal Response Interaction • Pact = A contract between Consumer and Provider • Each Pact is a collection of interactions Compare Reply Expected Request Minimal Response Interaction Provider State Pact – Contract between Consumer & Provider Once the Consumer Testing is done Pact file is generated by Pact Framework Pact Broker Publish Pacts to Pact Broker pact-broker publish --consumer-app-version 1.0.0 --broker-base-url https://broker.com --broker-token SomeToken /path/to/pacts/consumer-provider.json --tag master $>
  • 71. @arafkarsh arafkarsh PACT Architecture – Provider Testing 71 Review Service Mock Consumer Expected Request Minimal Response Interaction Provider State Compare Send Once the Consumer Testing is done Pact file is generated by Pact Framework Expected Request Minimal Response Interaction Provider State Pact – Contract between Consumer & Provider
  • 72. @arafkarsh arafkarsh Pact Definition Provider Name Consumer Name Contract Definition • @PactTestFor : Provider • @Pact : Consumer • Building Request / Response Pact 72
  • 73. @arafkarsh arafkarsh Pact Definition Consumer Name Contract Definition • @PactTestFor : Provider • @Pact : Consumer • Building Request / Response Pact • Running Consumer Pact Test 73
  • 74. @arafkarsh arafkarsh Pact Contract JSON 1. Contract Defines the Provider and Consumer 2. N number of Interactions can be defined under a single Contract 3. Interaction Defines Request, Response, Provider States, Rules etc. 4. Pact Specs v3.0 74
  • 75. @arafkarsh arafkarsh Pact : When to use? 75  Development of Consumer / Provider is controlled by your team/department/org.  No. of Consumers are small for a given Provider  Consumer and Provider are under active development.  Consumer Driven Contract – Provider features are driven by Consumer.  Provider team can easily control the data in the response. Pact is Good for When Source: https://docs.pact.io/getting_started/what_is_pact_good_for  Both teams (Consumer & Provider) don’t use Pact.  When the Consumers can’t be identified (Public APIs)  Functional / Behavior Testing of the Provider  Functionality is Driven by the Provider.  Performance and Load Testing  You can’t control the Response Data. Pact is NOT Good When
  • 76. @arafkarsh arafkarsh Comparison – Mockito / Pact # Feature Mockito WireMock Pact TEST SCOPE >>> API Wire Inter Service 1 Contract Testing Yes Yes Yes 2 Behavior / Functional Testing Yes 3 Test Double (Mock Provider) Yes 4 Consumer / Provider Testing using Shared Contract Yes 5 Mock System (For Consumer / Provider) Yes Yes 6 Multi Protocol Support (HTTP, Messaging) HTTP Yes 7 Centralized Contract Management Yes 8 API Documentation and Version Management Yes 9 Record and Playback Yes Yes 10 Supports JSON/XML Yes Yes 76
  • 77. @arafkarsh arafkarsh Microservices Testing Scenarios / Tools 77 Testing Tools Contract Testing Scope Integration Testing Verifies the communication paths and interactions between components to detect interface defects Contract Testing It is a test at the boundary of an external service verifying that it meets the contract expected by a consuming service. Payment Mock Integration Contract Testing Scope Test Double Montebank Cart Component Testing Unit Testing Integration Testing Scope Order REST / HTTP or Events / Kafka Item ID, Quantity, Address.. Mock Order Component Testing A component test limits the scope of the exercised software to a portion of the system under test. Order Payment Unit Testing Firewall Integration Testing Scope REST / HTTP Payment Sandbox Component Testing U
  • 78. @arafkarsh arafkarsh Microservices Testing Strategies 78 E2E Testing Integration Testing Contract Testing Component Testing Unit Testing Number of Tests Speed Cost Time Mike Cohen’s Testing Pyramid Test Pyramid: https://martinfowler.com/bliki/TestPyramid.html 75% 25% 0% Ubiquitous Language Domain Expert Analyst Developers QA Design Docs Test Cases Code Architect
  • 79. @arafkarsh arafkarsh Chaos Engineering – Load / Stress / Performance 79 Chaos Monkey Randomly disables production instances Chaos Kong Similar to Chaos Monkey, simulates an outage of an entire Amazon availability zone. Doctor Monkey Checks CPU load, Memory usage and removes it from network if the health is bad. Janitor Monkey Search for unused resources and disposes them. Compliance Monkey Finds instances that don’t adhere to best-practices and shuts them down. Latency Money Induces Artificial delays Security Monkey Is an extension of Compliance Monkey. Find security vulnerabilities and terminates offending instances. Source: https://github.com/Netflix/SimianArmy/wiki Source: http://principlesofchaos.org/
  • 80. @arafkarsh arafkarsh Testing Strategy Summary 80 1. Unit Testing A unit test exercises the smallest piece of testable software. 2. Component Testing A component test limits the scope of the exercised software to a portion of the system under test. 3. Contract Testing It is a test at the boundary of an external service verifying that it meets the contract expected by a consuming service 4. Integration Testing It verifies the communication paths and interactions between components to detect interface defects.
  • 81. @arafkarsh arafkarsh 81 100s Microservices 1,000s Releases / Day 10,000s Virtual Machines 100K+ User actions / Second 81 M Customers Globally 1 B Time series Metrics 10 B Hours of video streaming every quarter Source: NetFlix: : https://www.youtube.com/watch?v=UTKIT6STSVM 10s OPs Engineers 0 NOC 0 Data Centers So what do NetFlix think about DevOps? No DevOps Don’t do lot of Process / Procedures Freedom for Developers & be Accountable Trust people you Hire No Controls / Silos / Walls / Fences Ownership – You Build it, You Run it.
  • 82. @arafkarsh arafkarsh 82 Design Patterns are solutions to general problems that software developers faced during software development. Design Patterns
  • 83. @arafkarsh arafkarsh 83 DREAM | AUTOMATE | EMPOWER Araf Karsh Hamid : India: +91.999.545.8627 http://www.slideshare.net/arafkarsh https://www.linkedin.com/in/arafkarsh/ https://www.youtube.com/user/arafkarsh/playlists http://www.arafkarsh.com/ @arafkarsh arafkarsh
  • 84. @arafkarsh arafkarsh 84 Source Code: https://github.com/MetaArivu Web Site: https://metarivu.com/ https://pyxida.cloud/
  • 86. @arafkarsh arafkarsh References 1. July 15, 2015 – Agile is Dead : GoTo 2015 By Dave Thomas 2. Apr 7, 2016 - Agile Project Management with Kanban | Eric Brechner | Talks at Google 3. Sep 27, 2017 - Scrum vs Kanban - Two Agile Teams Go Head-to-Head 4. Feb 17, 2019 - Lean vs Agile vs Design Thinking 5. Dec 17, 2020 - Scrum vs Kanban | Differences & Similarities Between Scrum & Kanban 6. Feb 24, 2021 - Agile Methodology Tutorial for Beginners | Jira Tutorial | Agile Methodology Explained. Agile Methodologies 86
  • 87. @arafkarsh arafkarsh References 1. Vmware: What is Cloud Architecture? 2. Redhat: What is Cloud Architecture? 3. Cloud Computing Architecture 4. Cloud Adoption Essentials: 5. Google: Hybrid and Multi Cloud 6. IBM: Hybrid Cloud Architecture Intro 7. IBM: Hybrid Cloud Architecture: Part 1 8. IBM: Hybrid Cloud Architecture: Part 2 9. Cloud Computing Basics: IaaS, PaaS, SaaS 87 1. IBM: IaaS Explained 2. IBM: PaaS Explained 3. IBM: SaaS Explained 4. IBM: FaaS Explained 5. IBM: What is Hypervisor? Cloud Architecture
  • 88. @arafkarsh arafkarsh References Microservices 1. Microservices Definition by Martin Fowler 2. When to use Microservices By Martin Fowler 3. GoTo: Sep 3, 2020: When to use Microservices By Martin Fowler 4. GoTo: Feb 26, 2020: Monolith Decomposition Pattern 5. Thought Works: Microservices in a Nutshell 6. Microservices Prerequisites 7. What do you mean by Event Driven? 8. Understanding Event Driven Design Patterns for Microservices 88
  • 89. @arafkarsh arafkarsh References – Microservices – Videos 89 1. Martin Fowler – Micro Services : https://www.youtube.com/watch?v=2yko4TbC8cI&feature=youtu.be&t=15m53s 2. GOTO 2016 – Microservices at NetFlix Scale: Principles, Tradeoffs & Lessons Learned. By R Meshenberg 3. Mastering Chaos – A NetFlix Guide to Microservices. By Josh Evans 4. GOTO 2015 – Challenges Implementing Micro Services By Fred George 5. GOTO 2016 – From Monolith to Microservices at Zalando. By Rodrigue Scaefer 6. GOTO 2015 – Microservices @ Spotify. By Kevin Goldsmith 7. Modelling Microservices @ Spotify : https://www.youtube.com/watch?v=7XDA044tl8k 8. GOTO 2015 – DDD & Microservices: At last, Some Boundaries By Eric Evans 9. GOTO 2016 – What I wish I had known before Scaling Uber to 1000 Services. By Matt Ranney 10. DDD Europe – Tackling Complexity in the Heart of Software By Eric Evans, April 11, 2016 11. AWS re:Invent 2016 – From Monolithic to Microservices: Evolving Architecture Patterns. By Emerson L, Gilt D. Chiles 12. AWS 2017 – An overview of designing Microservices based Applications on AWS. By Peter Dalbhanjan 13. GOTO Jun, 2017 – Effective Microservices in a Data Centric World. By Randy Shoup. 14. GOTO July, 2017 – The Seven (more) Deadly Sins of Microservices. By Daniel Bryant 15. Sept, 2017 – Airbnb, From Monolith to Microservices: How to scale your Architecture. By Melanie Cubula 16. GOTO Sept, 2017 – Rethinking Microservices with Stateful Streams. By Ben Stopford. 17. GOTO 2017 – Microservices without Servers. By Glynn Bird.
  • 90. @arafkarsh arafkarsh References 90 Domain Driven Design 1. Oct 27, 2012 What I have learned about DDD Since the book. By Eric Evans 2. Mar 19, 2013 Domain Driven Design By Eric Evans 3. Jun 02, 2015 Applied DDD in Java EE 7 and Open Source World 4. Aug 23, 2016 Domain Driven Design the Good Parts By Jimmy Bogard 5. Sep 22, 2016 GOTO 2015 – DDD & REST Domain Driven API’s for the Web. By Oliver Gierke 6. Jan 24, 2017 Spring Developer – Developing Micro Services with Aggregates. By Chris Richardson 7. May 17. 2017 DEVOXX – The Art of Discovering Bounded Contexts. By Nick Tune 8. Dec 21, 2019 What is DDD - Eric Evans - DDD Europe 2019. By Eric Evans 9. Oct 2, 2020 - Bounded Contexts - Eric Evans - DDD Europe 2020. By. Eric Evans 10. Oct 2, 2020 - DDD By Example - Paul Rayner - DDD Europe 2020. By Paul Rayner
  • 91. @arafkarsh arafkarsh References Event Sourcing and CQRS 1. IBM: Event Driven Architecture – Mar 21, 2021 2. Martin Fowler: Event Driven Architecture – GOTO 2017 3. Greg Young: A Decade of DDD, Event Sourcing & CQRS – April 11, 2016 4. Nov 13, 2014 GOTO 2014 – Event Sourcing. By Greg Young 5. Mar 22, 2016 Building Micro Services with Event Sourcing and CQRS 6. Apr 15, 2016 YOW! Nights – Event Sourcing. By Martin Fowler 7. May 08, 2017 When Micro Services Meet Event Sourcing. By Vinicius Gomes 91
  • 92. @arafkarsh arafkarsh References 92 Kafka 1. Understanding Kafka 2. Understanding RabbitMQ 3. IBM: Apache Kafka – Sept 18, 2020 4. Confluent: Apache Kafka Fundamentals – April 25, 2020 5. Confluent: How Kafka Works – Aug 25, 2020 6. Confluent: How to integrate Kafka into your environment – Aug 25, 2020 7. Kafka Streams – Sept 4, 2021 8. Kafka: Processing Streaming Data with KSQL – Jul 16, 2018 9. Kafka: Processing Streaming Data with KSQL – Nov 28, 2019
  • 93. @arafkarsh arafkarsh References Databases: Big Data / Cloud Databases 1. Google: How to Choose the right database? 2. AWS: Choosing the right Database 3. IBM: NoSQL Vs. SQL 4. A Guide to NoSQL Databases 5. How does NoSQL Databases Work? 6. What is Better? SQL or NoSQL? 7. What is DBaaS? 8. NoSQL Concepts 9. Key Value Databases 10. Document Databases 11. Jun 29, 2012 – Google I/O 2012 - SQL vs NoSQL: Battle of the Backends 12. Feb 19, 2013 - Introduction to NoSQL • Martin Fowler • GOTO 2012 13. Jul 25, 2018 - SQL vs NoSQL or MySQL vs MongoDB 14. Oct 30, 2020 - Column vs Row Oriented Databases Explained 15. Dec 9, 2020 - How do NoSQL databases work? Simply Explained! 1. Graph Databases 2. Column Databases 3. Row Vs. Column Oriented Databases 4. Database Indexing Explained 5. MongoDB Indexing 6. AWS: DynamoDB Global Indexing 7. AWS: DynamoDB Local Indexing 8. Google Cloud Spanner 9. AWS: DynamoDB Design Patterns 10. Cloud Provider Database Comparisons 11. CockroachDB: When to use a Cloud DB? 93
  • 94. @arafkarsh arafkarsh References Docker / Kubernetes / Istio 1. IBM: Virtual Machines and Containers 2. IBM: What is a Hypervisor? 3. IBM: Docker Vs. Kubernetes 4. IBM: Containerization Explained 5. IBM: Kubernetes Explained 6. IBM: Kubernetes Ingress in 5 Minutes 7. Microsoft: How Service Mesh works in Kubernetes 8. IBM: Istio Service Mesh Explained 9. IBM: Kubernetes and OpenShift 10. IBM: Kubernetes Operators 11. 10 Consideration for Kubernetes Deployments Istio – Metrics 1. Istio – Metrics 2. Monitoring Istio Mesh with Grafana 3. Visualize your Istio Service Mesh 4. Security and Monitoring with Istio 5. Observing Services using Prometheus, Grafana, Kiali 6. Istio Cookbook: Kiali Recipe 7. Kubernetes: Open Telemetry 8. Open Telemetry 9. How Prometheus works 10. IBM: Observability vs. Monitoring 94
  • 95. @arafkarsh arafkarsh References 95 1. Feb 6, 2020 – An introduction to TDD 2. Aug 14, 2019 – Component Software Testing 3. May 30, 2020 – What is Component Testing? 4. Apr 23, 2013 – Component Test By Martin Fowler 5. Jan 12, 2011 – Contract Testing By Martin Fowler 6. Jan 16, 2018 – Integration Testing By Martin Fowler 7. Testing Strategies in Microservices Architecture 8. Practical Test Pyramid By Ham Vocke Testing – TDD / BDD
  • 96. @arafkarsh arafkarsh 96 1. Simoorg : LinkedIn’s own failure inducer framework. It was designed to be easy to extend and most of the important components are plug‐ gable. 2. Pumba : A chaos testing and network emulation tool for Docker. 3. Chaos Lemur : Self-hostable application to randomly destroy virtual machines in a BOSH- managed environment, as an aid to resilience testing of high-availability systems. 4. Chaos Lambda : Randomly terminate AWS ASG instances during business hours. 5. Blockade : Docker-based utility for testing network failures and partitions in distributed applications. 6. Chaos-http-proxy : Introduces failures into HTTP requests via a proxy server. 7. Monkey-ops : Monkey-Ops is a simple service implemented in Go, which is deployed into an OpenShift V3.X and generates some chaos within it. Monkey-Ops seeks some OpenShift components like Pods or Deployment Configs and randomly terminates them. 8. Chaos Dingo : Chaos Dingo currently supports performing operations on Azure VMs and VMSS deployed to an Azure Resource Manager-based resource group. 9. Tugbot : Testing in Production (TiP) framework for Docker. Testing tools
  • 97. @arafkarsh arafkarsh References CI / CD 1. What is Continuous Integration? 2. What is Continuous Delivery? 3. CI / CD Pipeline 4. What is CI / CD Pipeline? 5. CI / CD Explained 6. CI / CD Pipeline using Java Example Part 1 7. CI / CD Pipeline using Ansible Part 2 8. Declarative Pipeline vs Scripted Pipeline 9. Complete Jenkins Pipeline Tutorial 10. Common Pipeline Mistakes 11. CI / CD for a Docker Application 97
  • 98. @arafkarsh arafkarsh References 98 DevOps 1. IBM: What is DevOps? 2. IBM: Cloud Native DevOps Explained 3. IBM: Application Transformation 4. IBM: Virtualization Explained 5. What is DevOps? Easy Way 6. DevOps?! How to become a DevOps Engineer??? 7. Amazon: https://www.youtube.com/watch?v=mBU3AJ3j1rg 8. NetFlix: https://www.youtube.com/watch?v=UTKIT6STSVM 9. DevOps and SRE: https://www.youtube.com/watch?v=uTEL8Ff1Zvk 10. SLI, SLO, SLA : https://www.youtube.com/watch?v=tEylFyxbDLE 11. DevOps and SRE : Risks and Budgets : https://www.youtube.com/watch?v=y2ILKr8kCJU 12. SRE @ Google: https://www.youtube.com/watch?v=d2wn_E1jxn4
  • 99. @arafkarsh arafkarsh References 99 1. Lewis, James, and Martin Fowler. “Microservices: A Definition of This New Architectural Term”, March 25, 2014. 2. Miller, Matt. “Innovate or Die: The Rise of Microservices”. e Wall Street Journal, October 5, 2015. 3. Newman, Sam. Building Microservices. O’Reilly Media, 2015. 4. Alagarasan, Vijay. “Seven Microservices Anti-patterns”, August 24, 2015. 5. Cockcroft, Adrian. “State of the Art in Microservices”, December 4, 2014. 6. Fowler, Martin. “Microservice Prerequisites”, August 28, 2014. 7. Fowler, Martin. “Microservice Tradeoffs”, July 1, 2015. 8. Humble, Jez. “Four Principles of Low-Risk Software Release”, February 16, 2012. 9. Zuul Edge Server, Ketan Gote, May 22, 2017 10. Ribbon, Hysterix using Spring Feign, Ketan Gote, May 22, 2017 11. Eureka Server with Spring Cloud, Ketan Gote, May 22, 2017 12. Apache Kafka, A Distributed Streaming Platform, Ketan Gote, May 20, 2017 13. Functional Reactive Programming, Araf Karsh Hamid, August 7, 2016 14. Enterprise Software Architectures, Araf Karsh Hamid, July 30, 2016 15. Docker and Linux Containers, Araf Karsh Hamid, April 28, 2015
  • 100. @arafkarsh arafkarsh References 100 16. MSDN – Microsoft https://msdn.microsoft.com/en-us/library/dn568103.aspx 17. Martin Fowler : CQRS – http://martinfowler.com/bliki/CQRS.html 18. Udi Dahan : CQRS – http://www.udidahan.com/2009/12/09/clarified-cqrs/ 19. Greg Young : CQRS - https://www.youtube.com/watch?v=JHGkaShoyNs 20. Bertrand Meyer – CQS - http://en.wikipedia.org/wiki/Bertrand_Meyer 21. CQS : http://en.wikipedia.org/wiki/Command–query_separation 22. CAP Theorem : http://en.wikipedia.org/wiki/CAP_theorem 23. CAP Theorem : http://www.julianbrowne.com/article/viewer/brewers-cap-theorem 24. CAP 12 years how the rules have changed 25. EBay Scalability Best Practices : http://www.infoq.com/articles/ebay-scalability-best-practices 26. Pat Helland (Amazon) : Life beyond distributed transactions 27. Stanford University: Rx https://www.youtube.com/watch?v=y9xudo3C1Cw 28. Princeton University: SAGAS (1987) Hector Garcia Molina / Kenneth Salem 29. Rx Observable : https://dzone.com/articles/using-rx-java-observable

Editor's Notes

  1. https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html
  2. https://medium.com/netflix-techblog/the-netflix-simian-army-16e57fbab116
  3. DevOps Amazon: https://www.youtube.com/watch?v=mBU3AJ3j1rg NetFlix: https://www.youtube.com/watch?v=UTKIT6STSVM DevOps and SRE: https://www.youtube.com/watch?v=uTEL8Ff1Zvk SLI, SLO, SLA : https://www.youtube.com/watch?v=tEylFyxbDLE DevOps and SRE : Risks and Budgets : https://www.youtube.com/watch?v=y2ILKr8kCJU