SlideShare a Scribd company logo
1 of 43
Download to read offline
How to create modular
microservice test projects
Elias Nogueira
Elias Nogueira
I help professional software engineers
(backend, frontend, qa) to develop their quality
mindset and deliver bug-free software so they
become top-level engineers and get hired for
the best positions in the market.
🏢 Backbase
👨💻‍‍ Principal Software Engineer
📍 Utrecht, the Netherlands
🌐 eliasnogueira.com
🐦 @eliasnogueira
bit.ly/eliasnogueira
What problem do we
want to solve?
Implicitly we want …
● Increase confidence in delivery
● Cover key business scenarios
● The certainty that the test will find a possible failure
after some modification
API anatomy (testing perspective)
Individual APIs
API
API
API
A
P
I
A
P
I
API
A
P
I
A
P
I
Each microservice is a small feature that runs in isolation.
Individual APIs
Unit Tests
done!
API
API
API
A
P
I
A
P
I
API
A
P
I
A
P
I
Each API must have its unit tests and integration.
Integration
Tests* done!
* API Tests running in an
integration layer with or
without mocks
API
API
API
A
P
I
A
P
I
API
A
P
I
A
P
I
The problem
Integration tests won’t cover real scenarios of dependent APIs
because of the mocks.
depends
c
o
n
s
u
m
e
s
Possible solution
API
API
API
A
P
I
A
P
I
API
A
P
I
A
P
I
Possible solution
Create functional tests and e2e to cover possible gaps and
decrease the test on the UI.
Functional
Tests
&
E2E
API
API
API
A
P
I
A
P
I
API
A
P
I
A
P
I
Possible solution
What
Add tests to any kind of dependencies, as well for the user journey
depends
c
o
n
s
u
m
e
s
Analogy: buying a flight ticket
Buying a flight ticket
We must make sure each API is self-tested
unit -> integration -> functional
Search Flight selection Payment Confirmation
API API API API
Buying a flight ticket
We must make sure each API is self-tested
unit -> integration -> functional
Search Flight selection Payment Confirmation
Valid dates
Invalid return date
No flights found
API API API API
Buying a flight ticket
We must make sure each API is self-tested
e2e: buy a round-trip flight
Search Flight selection Payment Confirmation
Select valid
dates
API API API API
Select a flight
with seats
available Make a
payment with
valid data Successful
notification
E2E Scenario
How can test projects be
created?
Model 1
A test project for all microservices
BACKEND TEST
TEST
PROJECT
Model 1
Pros
● Centralization of code in a single project
● Speed and agility in creating tests and solving problems
Cons
● Constant changes by several people can have side effects on
results
Model 2
A test project for each microservice where interactions
with the endpoint (s) will be in the test project.
BACKEND
TEST TEST TEST
TEST
PROJECT
Model 2
Pros
● Organized decentralization of test projects towards an API
● Isolation between APIs
Cons
● Possible code duplication
Model 3
A test project for each microservice divided into client and
test projects
BACKEND
TEST
PROJECT
TEST TEST TEST
CLIENT CLIENT CLIENT
Model 3
Client project
We will put here all the necessary logic to make the
requests as:
○ Exception return
○ Transport Objects
○ Request call
○ Customizations for validations
○ Pointing settings (URI, base path, port)
Model 3
Test Project
We will put here all the methods of using the API we
created in the client project, creating the testing logic
and validating the results.
In summary, all tests are created here!
Model 3
Pros
● Greater version management (new features, breaking changes)
● Easy use by other teams
○ they just need to consume the customer and create their tests
Cons
● Time increase compared to previous models
Implementation exemple
Implementation example
Project separation
BACKEND
TEST
PROJECT
TEST TEST TEST
CLIENT CLIENT CLIENT
COMMONS
PARENT
Project separation
CLIENT
TEST
COMMONS
PARENT
Project containing all calls to the microservice, whether the calls
were successful or simulating exceptions.
Project containing tests for the microservice, testing its
functionality and dependencies with other microservices.
Code and libraries common to clients such as URL definitions,
authentication, and any other shared code.
Code and libraries common to tests such as data mass, support
functions, or any code common to tests.
Microservice examples
Possible graphical interface: Constraint check by CPF
We should inform a CPF
* Its a Brazilian social
security number
If a restriction is found,
show a message
Microservice examples
Possible graphical interface:
Loan Simulation
Fill in loan
information
Microservice examples
We will put here all the necessary logic to make
the requests as:
RESTRICTIONS
GET /api/v1/restricrions/{cpf}
GET /api/v2/restricrions/{cpf}
Constraint Query
API
SIMULATIONS
GET /api/v1/simulations/
GET /api/v1/simulations/{cpf}
POST /api/v1/simulations/
PUT /api/v1/simulations/{cpf}
DELETE /api/v1/simulations/{cpf}
Credit Simulation
API
Client’s implementation
Methods will be created to simulate all possible calls from
each HTTP method
CLIENT
RESTRICTIONS
GET /api/v1/restricrions/{cpf}
Constaint Query
API Client
Method - find CPF
Method - find CPF and return an exception
CLIENT
SIMULATIONS
GET /api/v1/simulations/
GET /api/v1/simulations/{cpf}
POST /api/v1/simulations/
Credit Simulation
Client API
Method – find all simulations
Method – find a simulation by a given CPF
Method – find a simulation by a given CPF and return not found
Method – submit a simulation
Method – submit a simulation and return unprocessable entity
Method – submit a simulation and return conflict
Methods will be created to simulate all possible calls from
each HTTP method
Client’s implementation
CLIENT
SIMULATIONS
POST /api/v1/simulations/
Credit Simulation
Client API
Method – submit a simulation
A test method will be created for one or more use of the
methods on the client
Test implementation
TEST
SIMULATIONS
should create a successful simulation - Test
Credit Simulation
Test Project
CLIENT
SIMULATIONS
POST /api/v1/simulations/
Method – submit a simulation and return unprocessable entity
A test method will be created for one or more use of the
methods on the client
TEST
SIMULATIONS
should show an error regarding an attribute not sent in the request
- Test
- Test
Credit Simulation
Client API
Credit Simulation
Test Project
Test implementation
Method – submit a simulation
should create a successful simulation
CLIENT
SIMULATIONS
POST /api/v1/simulations/
Method – submit a simulation and return conflict
TEST
SIMULATIONS
should show conflict when CPF already exists - Test
Credit Simulation
Client API
Credit Simulation
Test Project
A test method will be created for one or more use of the
methods on the client
Test implementation
Method – submit a simulation and return unprocessable entity
should show an error regarding an attribute not sent in the request
- Test
- Test
Method – submit a simulation
should create a successful simulation
How to use client <-> test?
How to use client <-> test?
Through the client version
● We must add the client dependency in the test
<dependency>
<groupId>com.eliasnogueira</groupId>
<artifactId>simulations-client</artifactId>
<version>1.2.5</version>
</dependency>
"devDependencies": {
"@eliasnogueira/simulations-client": ”1.2.5",
}
Java + Maven example
Typescript + Node example
How to use client <-> test?
Pros: association of the client
with the microservice version
Just as the microservice evolves the
client and the test evolve. Adding a
changelog with the association of the
client version with the microservice
version can help fix bugs.
Also tags helps if you would like to track
the evolution.
Recap
Recap
● We created a robust model for
○ test a microservice in isolation (functional test)
○ test a microservice and its dependencies (e2e)
● We modularize the creation of projects
○ client: the entire API call for a microservice
○ test: test project using the microservice client
○ commons: client codes and libraries
○ parent: test code and libraries
Thank you! SCAN ME
You can follow me on Twitter
@eliasnogueira and find the
practical examples of this
presentation. Be sure to
simulate the examples in the
code!
Projects
• https://github.com/eliasnogueira/test-parent
• https://github.com/eliasnogueira/test-commons
• https://github.com/eliasnogueira/restrictions-client
• https://github.com/eliasnogueira/restrictions-test
• https://github.com/eliasnogueira/simulations-client
• https://github.com/eliasnogueira/simulations-test
Important note
To be able to run the Project locally, after you clone it, you
must configure the GitHub Packages in your pom.xml file.
You can find the example here:
https://docs.github.com/en/packages/working-with-a-github-
packages-registry/working-with-the-apache-maven-registry
Replace the OWNER by eliasnogueira

More Related Content

Similar to How_to_create_modular_microservice_test_projects.pdf

Diving into the World of Test Automation The Approach and the Technologies
Diving into the World of Test Automation The Approach and the TechnologiesDiving into the World of Test Automation The Approach and the Technologies
Diving into the World of Test Automation The Approach and the TechnologiesQASymphony
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage [WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage WSO2
 
MuleSoft Certified Platform Architect Exam Dumps 2023.pdf
MuleSoft Certified Platform Architect Exam Dumps 2023.pdfMuleSoft Certified Platform Architect Exam Dumps 2023.pdf
MuleSoft Certified Platform Architect Exam Dumps 2023.pdfSkillCertProExams
 
Pivotal + Apigee Workshop (June 4th, 2019)
Pivotal + Apigee Workshop (June 4th, 2019)Pivotal + Apigee Workshop (June 4th, 2019)
Pivotal + Apigee Workshop (June 4th, 2019)Alexandre Roman
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App PresentationElizabeth Long
 
Software Testing - Online Guide
Software Testing - Online GuideSoftware Testing - Online Guide
Software Testing - Online Guidebigspire
 
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...Simplilearn
 
Enterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesEnterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesHemang Rindani
 
Enterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesEnterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesCygnet Infotech
 
#APIOps- Agile API Development powered by API Connect
#APIOps- Agile API Development powered by API Connect#APIOps- Agile API Development powered by API Connect
#APIOps- Agile API Development powered by API Connectpramodvallanur
 
QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1Akash Tyagi
 
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...Jitendra Bafna
 
Coml Psg Automation Approach
Coml Psg Automation ApproachComl Psg Automation Approach
Coml Psg Automation Approachroopavani
 
VishalSinha_Resume_Ora
VishalSinha_Resume_OraVishalSinha_Resume_Ora
VishalSinha_Resume_OraVishal Sinha
 
MuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam QuestionsMuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam Questionsdouglascarnicelli
 

Similar to How_to_create_modular_microservice_test_projects.pdf (20)

Ashish Baraiya
Ashish BaraiyaAshish Baraiya
Ashish Baraiya
 
Diving into the World of Test Automation The Approach and the Technologies
Diving into the World of Test Automation The Approach and the TechnologiesDiving into the World of Test Automation The Approach and the Technologies
Diving into the World of Test Automation The Approach and the Technologies
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage [WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
 
MuleSoft Certified Platform Architect Exam Dumps 2023.pdf
MuleSoft Certified Platform Architect Exam Dumps 2023.pdfMuleSoft Certified Platform Architect Exam Dumps 2023.pdf
MuleSoft Certified Platform Architect Exam Dumps 2023.pdf
 
Pivotal + Apigee Workshop (June 4th, 2019)
Pivotal + Apigee Workshop (June 4th, 2019)Pivotal + Apigee Workshop (June 4th, 2019)
Pivotal + Apigee Workshop (June 4th, 2019)
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Software Testing - Online Guide
Software Testing - Online GuideSoftware Testing - Online Guide
Software Testing - Online Guide
 
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
Introduction To DevOps | Devops Tutorial For Beginners | DevOps Training For ...
 
Vandana B
Vandana BVandana B
Vandana B
 
Prasanth
PrasanthPrasanth
Prasanth
 
Enterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesEnterprise QA and Application Testing Services
Enterprise QA and Application Testing Services
 
Enterprise QA and Application Testing Services
Enterprise QA and Application Testing ServicesEnterprise QA and Application Testing Services
Enterprise QA and Application Testing Services
 
#APIOps- Agile API Development powered by API Connect
#APIOps- Agile API Development powered by API Connect#APIOps- Agile API Development powered by API Connect
#APIOps- Agile API Development powered by API Connect
 
QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1
 
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...
MuleSoft Surat Virtual Meetup#31 - Async API, Process Error, Circuit Breaker ...
 
Coml Psg Automation Approach
Coml Psg Automation ApproachComl Psg Automation Approach
Coml Psg Automation Approach
 
VishalSinha_Resume_Ora
VishalSinha_Resume_OraVishalSinha_Resume_Ora
VishalSinha_Resume_Ora
 
Project P Open Workshop
Project P Open WorkshopProject P Open Workshop
Project P Open Workshop
 
MuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam QuestionsMuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam Questions
 

Recently uploaded

(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Species composition, diversity and community structure of mangroves in Barang...
Species composition, diversity and community structure of mangroves in Barang...Species composition, diversity and community structure of mangroves in Barang...
Species composition, diversity and community structure of mangroves in Barang...Open Access Research Paper
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Sustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesSustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesDr. Salem Baidas
 
See How do animals kill their prey for food
See How do animals kill their prey for foodSee How do animals kill their prey for food
See How do animals kill their prey for fooddrsk203
 
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一F dds
 
9873940964 High Profile Call Girls Delhi |Defence Colony ( MAYA CHOPRA ) DE...
9873940964 High Profile  Call Girls  Delhi |Defence Colony ( MAYA CHOPRA ) DE...9873940964 High Profile  Call Girls  Delhi |Defence Colony ( MAYA CHOPRA ) DE...
9873940964 High Profile Call Girls Delhi |Defence Colony ( MAYA CHOPRA ) DE...Delhi Escorts
 
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...Suhani Kapoor
 
Determination of antibacterial activity of various broad spectrum antibiotics...
Determination of antibacterial activity of various broad spectrum antibiotics...Determination of antibacterial activity of various broad spectrum antibiotics...
Determination of antibacterial activity of various broad spectrum antibiotics...Open Access Research Paper
 
Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BHbill846304
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...Cluster TWEED
 
Along the Lakefront, "Menacing Unknown"s
Along the Lakefront, "Menacing Unknown"sAlong the Lakefront, "Menacing Unknown"s
Along the Lakefront, "Menacing Unknown"syalehistoricalreview
 
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...Suhani Kapoor
 

Recently uploaded (20)

(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wagholi ( 7001035870 ) HI-Fi Pune Escorts Service
 
Species composition, diversity and community structure of mangroves in Barang...
Species composition, diversity and community structure of mangroves in Barang...Species composition, diversity and community structure of mangroves in Barang...
Species composition, diversity and community structure of mangroves in Barang...
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
FULL ENJOY Call Girls In kashmiri gate (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In  kashmiri gate (Delhi) Call Us 9953056974FULL ENJOY Call Girls In  kashmiri gate (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In kashmiri gate (Delhi) Call Us 9953056974
 
Sustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesSustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and Challenges
 
See How do animals kill their prey for food
See How do animals kill their prey for foodSee How do animals kill their prey for food
See How do animals kill their prey for food
 
Green Banking
Green Banking Green Banking
Green Banking
 
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(RIYA) Kalyani Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
 
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一
办理学位证(KU证书)堪萨斯大学毕业证成绩单原版一比一
 
9873940964 High Profile Call Girls Delhi |Defence Colony ( MAYA CHOPRA ) DE...
9873940964 High Profile  Call Girls  Delhi |Defence Colony ( MAYA CHOPRA ) DE...9873940964 High Profile  Call Girls  Delhi |Defence Colony ( MAYA CHOPRA ) DE...
9873940964 High Profile Call Girls Delhi |Defence Colony ( MAYA CHOPRA ) DE...
 
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...
VIP Call Girls Ramanthapur ( Hyderabad ) Phone 8250192130 | ₹5k To 25k With R...
 
Hot Sexy call girls in Nehru Place, 🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Nehru Place, 🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Nehru Place, 🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Nehru Place, 🔝 9953056974 🔝 escort Service
 
Determination of antibacterial activity of various broad spectrum antibiotics...
Determination of antibacterial activity of various broad spectrum antibiotics...Determination of antibacterial activity of various broad spectrum antibiotics...
Determination of antibacterial activity of various broad spectrum antibiotics...
 
Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BH
 
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
webinaire-green-mirror-episode-2-Smart contracts and virtual purchase agreeme...
 
Along the Lakefront, "Menacing Unknown"s
Along the Lakefront, "Menacing Unknown"sAlong the Lakefront, "Menacing Unknown"s
Along the Lakefront, "Menacing Unknown"s
 
Escort Service Call Girls In Shakti Nagar, 99530°56974 Delhi NCR
Escort Service Call Girls In Shakti Nagar, 99530°56974 Delhi NCREscort Service Call Girls In Shakti Nagar, 99530°56974 Delhi NCR
Escort Service Call Girls In Shakti Nagar, 99530°56974 Delhi NCR
 
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
 

How_to_create_modular_microservice_test_projects.pdf

  • 1. How to create modular microservice test projects Elias Nogueira
  • 2. Elias Nogueira I help professional software engineers (backend, frontend, qa) to develop their quality mindset and deliver bug-free software so they become top-level engineers and get hired for the best positions in the market. 🏢 Backbase 👨💻‍‍ Principal Software Engineer 📍 Utrecht, the Netherlands 🌐 eliasnogueira.com 🐦 @eliasnogueira bit.ly/eliasnogueira
  • 3. What problem do we want to solve?
  • 4. Implicitly we want … ● Increase confidence in delivery ● Cover key business scenarios ● The certainty that the test will find a possible failure after some modification
  • 5. API anatomy (testing perspective)
  • 7. Individual APIs Unit Tests done! API API API A P I A P I API A P I A P I Each API must have its unit tests and integration. Integration Tests* done! * API Tests running in an integration layer with or without mocks
  • 8. API API API A P I A P I API A P I A P I The problem Integration tests won’t cover real scenarios of dependent APIs because of the mocks. depends c o n s u m e s
  • 10. API API API A P I A P I API A P I A P I Possible solution Create functional tests and e2e to cover possible gaps and decrease the test on the UI. Functional Tests & E2E
  • 11. API API API A P I A P I API A P I A P I Possible solution What Add tests to any kind of dependencies, as well for the user journey depends c o n s u m e s
  • 12. Analogy: buying a flight ticket
  • 13. Buying a flight ticket We must make sure each API is self-tested unit -> integration -> functional Search Flight selection Payment Confirmation API API API API
  • 14. Buying a flight ticket We must make sure each API is self-tested unit -> integration -> functional Search Flight selection Payment Confirmation Valid dates Invalid return date No flights found API API API API
  • 15. Buying a flight ticket We must make sure each API is self-tested e2e: buy a round-trip flight Search Flight selection Payment Confirmation Select valid dates API API API API Select a flight with seats available Make a payment with valid data Successful notification E2E Scenario
  • 16. How can test projects be created?
  • 17. Model 1 A test project for all microservices BACKEND TEST TEST PROJECT
  • 18. Model 1 Pros ● Centralization of code in a single project ● Speed and agility in creating tests and solving problems Cons ● Constant changes by several people can have side effects on results
  • 19. Model 2 A test project for each microservice where interactions with the endpoint (s) will be in the test project. BACKEND TEST TEST TEST TEST PROJECT
  • 20. Model 2 Pros ● Organized decentralization of test projects towards an API ● Isolation between APIs Cons ● Possible code duplication
  • 21. Model 3 A test project for each microservice divided into client and test projects BACKEND TEST PROJECT TEST TEST TEST CLIENT CLIENT CLIENT
  • 22. Model 3 Client project We will put here all the necessary logic to make the requests as: ○ Exception return ○ Transport Objects ○ Request call ○ Customizations for validations ○ Pointing settings (URI, base path, port)
  • 23. Model 3 Test Project We will put here all the methods of using the API we created in the client project, creating the testing logic and validating the results. In summary, all tests are created here!
  • 24. Model 3 Pros ● Greater version management (new features, breaking changes) ● Easy use by other teams ○ they just need to consume the customer and create their tests Cons ● Time increase compared to previous models
  • 26. Implementation example Project separation BACKEND TEST PROJECT TEST TEST TEST CLIENT CLIENT CLIENT COMMONS PARENT
  • 27. Project separation CLIENT TEST COMMONS PARENT Project containing all calls to the microservice, whether the calls were successful or simulating exceptions. Project containing tests for the microservice, testing its functionality and dependencies with other microservices. Code and libraries common to clients such as URL definitions, authentication, and any other shared code. Code and libraries common to tests such as data mass, support functions, or any code common to tests.
  • 28. Microservice examples Possible graphical interface: Constraint check by CPF We should inform a CPF * Its a Brazilian social security number If a restriction is found, show a message
  • 29. Microservice examples Possible graphical interface: Loan Simulation Fill in loan information
  • 30. Microservice examples We will put here all the necessary logic to make the requests as: RESTRICTIONS GET /api/v1/restricrions/{cpf} GET /api/v2/restricrions/{cpf} Constraint Query API SIMULATIONS GET /api/v1/simulations/ GET /api/v1/simulations/{cpf} POST /api/v1/simulations/ PUT /api/v1/simulations/{cpf} DELETE /api/v1/simulations/{cpf} Credit Simulation API
  • 31. Client’s implementation Methods will be created to simulate all possible calls from each HTTP method CLIENT RESTRICTIONS GET /api/v1/restricrions/{cpf} Constaint Query API Client Method - find CPF Method - find CPF and return an exception
  • 32. CLIENT SIMULATIONS GET /api/v1/simulations/ GET /api/v1/simulations/{cpf} POST /api/v1/simulations/ Credit Simulation Client API Method – find all simulations Method – find a simulation by a given CPF Method – find a simulation by a given CPF and return not found Method – submit a simulation Method – submit a simulation and return unprocessable entity Method – submit a simulation and return conflict Methods will be created to simulate all possible calls from each HTTP method Client’s implementation
  • 33. CLIENT SIMULATIONS POST /api/v1/simulations/ Credit Simulation Client API Method – submit a simulation A test method will be created for one or more use of the methods on the client Test implementation TEST SIMULATIONS should create a successful simulation - Test Credit Simulation Test Project
  • 34. CLIENT SIMULATIONS POST /api/v1/simulations/ Method – submit a simulation and return unprocessable entity A test method will be created for one or more use of the methods on the client TEST SIMULATIONS should show an error regarding an attribute not sent in the request - Test - Test Credit Simulation Client API Credit Simulation Test Project Test implementation Method – submit a simulation should create a successful simulation
  • 35. CLIENT SIMULATIONS POST /api/v1/simulations/ Method – submit a simulation and return conflict TEST SIMULATIONS should show conflict when CPF already exists - Test Credit Simulation Client API Credit Simulation Test Project A test method will be created for one or more use of the methods on the client Test implementation Method – submit a simulation and return unprocessable entity should show an error regarding an attribute not sent in the request - Test - Test Method – submit a simulation should create a successful simulation
  • 36. How to use client <-> test?
  • 37. How to use client <-> test? Through the client version ● We must add the client dependency in the test <dependency> <groupId>com.eliasnogueira</groupId> <artifactId>simulations-client</artifactId> <version>1.2.5</version> </dependency> "devDependencies": { "@eliasnogueira/simulations-client": ”1.2.5", } Java + Maven example Typescript + Node example
  • 38. How to use client <-> test? Pros: association of the client with the microservice version Just as the microservice evolves the client and the test evolve. Adding a changelog with the association of the client version with the microservice version can help fix bugs. Also tags helps if you would like to track the evolution.
  • 39. Recap
  • 40. Recap ● We created a robust model for ○ test a microservice in isolation (functional test) ○ test a microservice and its dependencies (e2e) ● We modularize the creation of projects ○ client: the entire API call for a microservice ○ test: test project using the microservice client ○ commons: client codes and libraries ○ parent: test code and libraries
  • 41. Thank you! SCAN ME You can follow me on Twitter @eliasnogueira and find the practical examples of this presentation. Be sure to simulate the examples in the code!
  • 42. Projects • https://github.com/eliasnogueira/test-parent • https://github.com/eliasnogueira/test-commons • https://github.com/eliasnogueira/restrictions-client • https://github.com/eliasnogueira/restrictions-test • https://github.com/eliasnogueira/simulations-client • https://github.com/eliasnogueira/simulations-test
  • 43. Important note To be able to run the Project locally, after you clone it, you must configure the GitHub Packages in your pom.xml file. You can find the example here: https://docs.github.com/en/packages/working-with-a-github- packages-registry/working-with-the-apache-maven-registry Replace the OWNER by eliasnogueira