SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
How we can shift
testing left
Alisa Petivotova
Contract based testing
• Why
• What
• When
• How
• Who
2
AGENDA
All
about
contract
based
testing
3
Let’s talk about testing pyramid
UI
INT
UNIT
4
UISERVICESDB
Web UI
Backend
DB
S1
S2
S3
So how we can achieve it?
5
So how we can achieve it?
UISERVICESDB
Web UI
BFF
DB
S1
S2
S3
UISERVICESDB
Web UI
Backend
DB
S1
S2
S3
6
• Mostly manual smoke run
10
Manual
• Smoke tests run with deploy in TFS
• Roll back deploy if tests failed
• Testing team responsibility
39
UI
• Run with CI (TeamCity)
• Use Mocks
• Testing team responsibility
296
Integration
• Run with CI (TeamCity)
• Development team
responsibility
911
Unit
Test Automation TeamDev Team Manual Test Team
Let’s talk about testing pyramid
7
Integration test for a microservice
• Mock service for any outgoing http call
• Receive request and return response
• Verify any outgoing calls
CleanDB
• Clean DB
• Create new DB before test run
• Clear DB before each test
MockServices
localhost:1234
TestServer
• TestServer
• In-memory test server
• Able to dispatch requests using HttpClient
in-memorylocalhost:3333
8
Integration test for a microservice
PactBuilder =
new PactBuilder(new PactConfig
{
SpecificationVersion = "2.0.0",
Outputters = new XUnitOutput(_output),
PactDir = "../PactContracts"
})
.ServiceConsumer(consumer)
.HasPactWith(provider);
MockProviderService =
PactBuilder.MockService(port);
1. Start mock service
1234
MockServicesCleanDBTestServer
localhost:1234
9
Integration test for a microservice
var request = new ProviderServiceRequest
{
Method = HttpVerb.Get,
Path = "/search",
Query = $"searchText={searchString}"
};
var response = new ProviderServiceResponse
{
Status = 200,
Headers = /*content type headers, etc.*/
Body = data
};
MockService
.Given(testCaseName)
.UponReceiving(testCaseAction)
.With(request)
.WillRespondWith(response);
1. Start mock service
2. Register expected interaction
MockServicesCleanDBTestServer
localhost:1234
10
Testing UI component
1. Build Agents requirements:
• Node version installed to match your UI solution to run
• Browsers to match your tests requirements
2. Parallel run options:
• Docker containers – the easiest way to pass the image
• Build agents – pass the files directly from master to child jobs
3. Integration with devs CI pipeline requirements:
• Parallel test run under 15 mins
• Pass rate 100%
UI
localhost:3456
Servers
localhost:5000
00:00 00:15 00:30 00:45 01:00 01:15 01:30 01:45 02:00 02:15 02:30
Execution
Time
UI test execution time
Component UI (new approach) System UI E2E (old approach)
Let’s compare
11
10x
Execution
Time
0:00 0:07 0:14 0:21 0:28 0:36 0:43
API tests execution time
Integration tests (new approach) API tests (old approach)
15x
Prevent
defects
rather than
found them
4
Long process
of ensuring
contract
3
2
1
Defects in
PROD
Mocks did
not
guarantee
correctness
12
Testing contracts – why we started doing this
Contract Testing is a way to ensure that
services can communicate with each other.
Consumer Driven Contracts means that
contracts are created on consumer side.
Pact is a consumer-driven testing tool
13
Testing contracts
API
API
API
UI
API
v1
API
v2
Pact (noun):
A formal agreement between individuals or parties. “
The country negotiated a trade pact with the US"
Synonyms: agreement, protocol, deal, contract
~ Oxford Dictionaries
A Contract is a collection of agreements between
a client (Consumer) and an API (Provider) that
describes the interactions that can take place
between them.
What can be verified:
• Response and request structure
• Data types and data itself
• Status codes and headers
Technologies:
• Pact.Net
• Pact.JS
• Pact JVM
14
Testing contracts
1. Create contract from consumer side
PactBuilder.Build();
2. Publish contract to Pact Broker
(or any other location you like)
var pactPublisher =
new PactPublisher(PactBrokerUrl);
pactPublisher.PublishToBroker($"....pacts
{Consumer.ToLower()}-
{Provider.ToLower()}.json", “1.0.5");
15
Testing contracts – How To
3. Get contract file (from Pact Broker or any other location
you put it to) and verify contract against your service
var config = new PactVerifierConfig
{
Outputters = new List<IOutput>{new
XUnitOutput(output)},
PublishVerificationResults = true,
ProviderVersion = "0.0.0"
};
IPactVerifier pactVerifier = new PactVerifier(config);
pactVerifier
.ServiceProvider(provider, serviceUri)
.HonoursPactWith(consumer)
.ProviderState($"{serviceUri}{providerStatesUrl}")
.PactUri($"{pactBrokerUrl}/pacts" +
$"/provider/{provider}" +
$"/consumer/{consumer}/latest")
.Verify();
16
Testing contracts – How To
17
Testing contracts – What you’ll get
18
Testing contracts – What you’ll get
Provider service will respond with:
19
Testing contracts - Pact Broker
20
Testing contracts - Dependency graph
1 PACT is a buggy tool
2Limited functionality for .Net
3 Legacy applications
4Requires vertical integration
5 Convincing others to try
21
Testing contracts - challenges
22
What we getUISERVICESDB
Web UI
BFF
DB
S1
S2
S3
1
2
3
4
5
7 8
9
10
11
12
13
6
1 Happy Path E2E test
13 Integration tests
1 Your Apps will work together
2Continuously evolve codebase
3 No reinvention of the wheel
4Send only what’s needed
5 Get the dependencies graph
23
Testing contracts - benefits
How to get started
25
TRY IT
https://docs.pact.io/
26
Q&A
Thank you!
alisa_petivotova@epam.com
alisa.petivotova

Contenu connexe

Tendances

Tendances (20)

Securing Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad MeetupSecuring Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad Meetup
 
Database deployments - dotnetsheff
Database deployments - dotnetsheffDatabase deployments - dotnetsheff
Database deployments - dotnetsheff
 
How to build the Cloud Native applications the way you want – not the way the...
How to build the Cloud Native applications the way you want – not the way the...How to build the Cloud Native applications the way you want – not the way the...
How to build the Cloud Native applications the way you want – not the way the...
 
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedRebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
 
End-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.devEnd-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.dev
 
Rik Hepworth - ARM Yourself for Effective Azure Provisioning
Rik Hepworth - ARM Yourself for Effective Azure ProvisioningRik Hepworth - ARM Yourself for Effective Azure Provisioning
Rik Hepworth - ARM Yourself for Effective Azure Provisioning
 
Bringing Serverless into the Enterprise (Global Azure Virtual 2020)
Bringing Serverless into the Enterprise (Global Azure Virtual 2020)Bringing Serverless into the Enterprise (Global Azure Virtual 2020)
Bringing Serverless into the Enterprise (Global Azure Virtual 2020)
 
Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!Infrastructure as Code on Azure: Show your Bicep!
Infrastructure as Code on Azure: Show your Bicep!
 
Alex Magnay - Azure Infrastructure as Code with Hashicorp Terraform
Alex Magnay - Azure Infrastructure as Code with Hashicorp TerraformAlex Magnay - Azure Infrastructure as Code with Hashicorp Terraform
Alex Magnay - Azure Infrastructure as Code with Hashicorp Terraform
 
Azure Service Fabric: The road ahead for microservices
Azure Service Fabric: The road ahead for microservicesAzure Service Fabric: The road ahead for microservices
Azure Service Fabric: The road ahead for microservices
 
SPS calgary 2017 introduction to azure functions microsoft flow
SPS calgary 2017 introduction to azure functions microsoft flowSPS calgary 2017 introduction to azure functions microsoft flow
SPS calgary 2017 introduction to azure functions microsoft flow
 
DevOps Moves To Production (Lori MacVittie)
DevOps Moves To Production (Lori MacVittie)DevOps Moves To Production (Lori MacVittie)
DevOps Moves To Production (Lori MacVittie)
 
Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks
Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks
Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks
 
SPS vancouver is it possible to do devops with SharePoint Framework
SPS vancouver is it possible to do devops with SharePoint FrameworkSPS vancouver is it possible to do devops with SharePoint Framework
SPS vancouver is it possible to do devops with SharePoint Framework
 
ASP.NET Core deployment options
ASP.NET Core deployment optionsASP.NET Core deployment options
ASP.NET Core deployment options
 
PaaS and Container Innovation – What’s new with App Service
PaaS and Container Innovation – What’s new with App ServicePaaS and Container Innovation – What’s new with App Service
PaaS and Container Innovation – What’s new with App Service
 
.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric
 
Azure cli-azure devops
Azure cli-azure devopsAzure cli-azure devops
Azure cli-azure devops
 
Serverless in action
Serverless in actionServerless in action
Serverless in action
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
 

Similaire à Contract-based Testing Approach as a Tool for Shift Lef

Similaire à Contract-based Testing Approach as a Tool for Shift Lef (20)

Contract based testing
Contract based testingContract based testing
Contract based testing
 
Wading through treacle? Escape the integration syrup with contract tests
Wading through treacle? Escape the integration syrup with contract testsWading through treacle? Escape the integration syrup with contract tests
Wading through treacle? Escape the integration syrup with contract tests
 
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
 
From Zero to Serverless
From Zero to ServerlessFrom Zero to Serverless
From Zero to Serverless
 
Real-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTCReal-Time Communication Testing Evolution with WebRTC
Real-Time Communication Testing Evolution with WebRTC
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 
Deploying large-scale, serverless and asynchronous systems - without integrat...
Deploying large-scale, serverless and asynchronous systems - without integrat...Deploying large-scale, serverless and asynchronous systems - without integrat...
Deploying large-scale, serverless and asynchronous systems - without integrat...
 
Integration Testing as Validation and Monitoring
 Integration Testing as Validation and Monitoring Integration Testing as Validation and Monitoring
Integration Testing as Validation and Monitoring
 
Modern CI/CD Pipeline Using Azure DevOps
Modern CI/CD Pipeline Using Azure DevOpsModern CI/CD Pipeline Using Azure DevOps
Modern CI/CD Pipeline Using Azure DevOps
 
Debugging Integration Flows
Debugging Integration FlowsDebugging Integration Flows
Debugging Integration Flows
 
IBM Blockchain Platform - Architectural Good Practices v1.0
IBM Blockchain Platform - Architectural Good Practices v1.0IBM Blockchain Platform - Architectural Good Practices v1.0
IBM Blockchain Platform - Architectural Good Practices v1.0
 
ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2
 
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer ToolsA Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle Management
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure Functions
 
ENT201 A Tale of Two Pizzas: Accelerating Software Delivery with AWS Develope...
ENT201 A Tale of Two Pizzas: Accelerating Software Delivery with AWS Develope...ENT201 A Tale of Two Pizzas: Accelerating Software Delivery with AWS Develope...
ENT201 A Tale of Two Pizzas: Accelerating Software Delivery with AWS Develope...
 
ApacheCon Core: Service Discovery in OSGi: Beyond the JVM using Docker and Co...
ApacheCon Core: Service Discovery in OSGi: Beyond the JVM using Docker and Co...ApacheCon Core: Service Discovery in OSGi: Beyond the JVM using Docker and Co...
ApacheCon Core: Service Discovery in OSGi: Beyond the JVM using Docker and Co...
 
SRV312 DevOps on AWS: Building Systems to Deliver Faster
SRV312 DevOps on AWS: Building Systems to Deliver FasterSRV312 DevOps on AWS: Building Systems to Deliver Faster
SRV312 DevOps on AWS: Building Systems to Deliver Faster
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
 

Plus de Katherine Golovinova

Plus de Katherine Golovinova (20)

Speed up application testing with azure container instances
Speed up application testing with azure container instancesSpeed up application testing with azure container instances
Speed up application testing with azure container instances
 
Analyzing application activities with KSQL and Elasticsearch
Analyzing application activities with KSQL and ElasticsearchAnalyzing application activities with KSQL and Elasticsearch
Analyzing application activities with KSQL and Elasticsearch
 
Testing Big Data solutions fast and furiously
Testing Big Data solutions fast and furiouslyTesting Big Data solutions fast and furiously
Testing Big Data solutions fast and furiously
 
"Fast & Fail in real life of DevTestSecOps"
"Fast & Fail in real life of DevTestSecOps""Fast & Fail in real life of DevTestSecOps"
"Fast & Fail in real life of DevTestSecOps"
 
Geodistributed databases - what, how, and why?
Geodistributed databases - what, how, and why?Geodistributed databases - what, how, and why?
Geodistributed databases - what, how, and why?
 
COSMOS DB - geodistributed database for anyone
COSMOS DB - geodistributed database for anyoneCOSMOS DB - geodistributed database for anyone
COSMOS DB - geodistributed database for anyone
 
Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?
 
Azure Functions - the evolution of microservices platform or marketing gibber...
Azure Functions - the evolution of microservices platform or marketing gibber...Azure Functions - the evolution of microservices platform or marketing gibber...
Azure Functions - the evolution of microservices platform or marketing gibber...
 
Gatling and Page Object: a way to performance testing
Gatling and Page Object: a way to performance testingGatling and Page Object: a way to performance testing
Gatling and Page Object: a way to performance testing
 
Automation of Security scanning easy or cheese
Automation of Security scanning easy or cheeseAutomation of Security scanning easy or cheese
Automation of Security scanning easy or cheese
 
Gradle plugins for Test Automation
Gradle plugins for Test AutomationGradle plugins for Test Automation
Gradle plugins for Test Automation
 
Automation world under the DevTestSecOps umbrella
Automation world under the DevTestSecOps umbrellaAutomation world under the DevTestSecOps umbrella
Automation world under the DevTestSecOps umbrella
 
"Disaster Recovery in Azure" by Viktor Kocherha
"Disaster Recovery in Azure" by Viktor Kocherha"Disaster Recovery in Azure" by Viktor Kocherha
"Disaster Recovery in Azure" by Viktor Kocherha
 
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
 
"Modern CI/CD" by Dmytro Batiievskyi
"Modern CI/CD" by Dmytro Batiievskyi"Modern CI/CD" by Dmytro Batiievskyi
"Modern CI/CD" by Dmytro Batiievskyi
 
EPAM DevOps community meetup: Building CI/CD for microservice architecture
EPAM DevOps community meetup: Building CI/CD for microservice architectureEPAM DevOps community meetup: Building CI/CD for microservice architecture
EPAM DevOps community meetup: Building CI/CD for microservice architecture
 
EPAM DevOps community meetup: Designing bare metal Kubernetes clusters
EPAM DevOps community meetup: Designing bare metal Kubernetes clustersEPAM DevOps community meetup: Designing bare metal Kubernetes clusters
EPAM DevOps community meetup: Designing bare metal Kubernetes clusters
 
Hosting Microservices in Microsoft Azure
Hosting Microservices in Microsoft AzureHosting Microservices in Microsoft Azure
Hosting Microservices in Microsoft Azure
 
Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?
 
Azure IoT Hub: what is it and why we select other solution (production projec...
Azure IoT Hub: what is it and why we select other solution (production projec...Azure IoT Hub: what is it and why we select other solution (production projec...
Azure IoT Hub: what is it and why we select other solution (production projec...
 

Dernier

+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@
 

Dernier (20)

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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 

Contract-based Testing Approach as a Tool for Shift Lef

  • 1. How we can shift testing left Alisa Petivotova Contract based testing
  • 2. • Why • What • When • How • Who 2 AGENDA All about contract based testing
  • 3. 3 Let’s talk about testing pyramid UI INT UNIT
  • 5. 5 So how we can achieve it? UISERVICESDB Web UI BFF DB S1 S2 S3 UISERVICESDB Web UI Backend DB S1 S2 S3
  • 6. 6 • Mostly manual smoke run 10 Manual • Smoke tests run with deploy in TFS • Roll back deploy if tests failed • Testing team responsibility 39 UI • Run with CI (TeamCity) • Use Mocks • Testing team responsibility 296 Integration • Run with CI (TeamCity) • Development team responsibility 911 Unit Test Automation TeamDev Team Manual Test Team Let’s talk about testing pyramid
  • 7. 7 Integration test for a microservice • Mock service for any outgoing http call • Receive request and return response • Verify any outgoing calls CleanDB • Clean DB • Create new DB before test run • Clear DB before each test MockServices localhost:1234 TestServer • TestServer • In-memory test server • Able to dispatch requests using HttpClient in-memorylocalhost:3333
  • 8. 8 Integration test for a microservice PactBuilder = new PactBuilder(new PactConfig { SpecificationVersion = "2.0.0", Outputters = new XUnitOutput(_output), PactDir = "../PactContracts" }) .ServiceConsumer(consumer) .HasPactWith(provider); MockProviderService = PactBuilder.MockService(port); 1. Start mock service 1234 MockServicesCleanDBTestServer localhost:1234
  • 9. 9 Integration test for a microservice var request = new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/search", Query = $"searchText={searchString}" }; var response = new ProviderServiceResponse { Status = 200, Headers = /*content type headers, etc.*/ Body = data }; MockService .Given(testCaseName) .UponReceiving(testCaseAction) .With(request) .WillRespondWith(response); 1. Start mock service 2. Register expected interaction MockServicesCleanDBTestServer localhost:1234
  • 10. 10 Testing UI component 1. Build Agents requirements: • Node version installed to match your UI solution to run • Browsers to match your tests requirements 2. Parallel run options: • Docker containers – the easiest way to pass the image • Build agents – pass the files directly from master to child jobs 3. Integration with devs CI pipeline requirements: • Parallel test run under 15 mins • Pass rate 100% UI localhost:3456 Servers localhost:5000
  • 11. 00:00 00:15 00:30 00:45 01:00 01:15 01:30 01:45 02:00 02:15 02:30 Execution Time UI test execution time Component UI (new approach) System UI E2E (old approach) Let’s compare 11 10x Execution Time 0:00 0:07 0:14 0:21 0:28 0:36 0:43 API tests execution time Integration tests (new approach) API tests (old approach) 15x
  • 12. Prevent defects rather than found them 4 Long process of ensuring contract 3 2 1 Defects in PROD Mocks did not guarantee correctness 12 Testing contracts – why we started doing this
  • 13. Contract Testing is a way to ensure that services can communicate with each other. Consumer Driven Contracts means that contracts are created on consumer side. Pact is a consumer-driven testing tool 13 Testing contracts API API API UI API v1 API v2 Pact (noun): A formal agreement between individuals or parties. “ The country negotiated a trade pact with the US" Synonyms: agreement, protocol, deal, contract ~ Oxford Dictionaries
  • 14. A Contract is a collection of agreements between a client (Consumer) and an API (Provider) that describes the interactions that can take place between them. What can be verified: • Response and request structure • Data types and data itself • Status codes and headers Technologies: • Pact.Net • Pact.JS • Pact JVM 14 Testing contracts
  • 15. 1. Create contract from consumer side PactBuilder.Build(); 2. Publish contract to Pact Broker (or any other location you like) var pactPublisher = new PactPublisher(PactBrokerUrl); pactPublisher.PublishToBroker($"....pacts {Consumer.ToLower()}- {Provider.ToLower()}.json", “1.0.5"); 15 Testing contracts – How To
  • 16. 3. Get contract file (from Pact Broker or any other location you put it to) and verify contract against your service var config = new PactVerifierConfig { Outputters = new List<IOutput>{new XUnitOutput(output)}, PublishVerificationResults = true, ProviderVersion = "0.0.0" }; IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider(provider, serviceUri) .HonoursPactWith(consumer) .ProviderState($"{serviceUri}{providerStatesUrl}") .PactUri($"{pactBrokerUrl}/pacts" + $"/provider/{provider}" + $"/consumer/{consumer}/latest") .Verify(); 16 Testing contracts – How To
  • 17. 17 Testing contracts – What you’ll get
  • 18. 18 Testing contracts – What you’ll get Provider service will respond with:
  • 19. 19 Testing contracts - Pact Broker
  • 20. 20 Testing contracts - Dependency graph
  • 21. 1 PACT is a buggy tool 2Limited functionality for .Net 3 Legacy applications 4Requires vertical integration 5 Convincing others to try 21 Testing contracts - challenges
  • 22. 22 What we getUISERVICESDB Web UI BFF DB S1 S2 S3 1 2 3 4 5 7 8 9 10 11 12 13 6 1 Happy Path E2E test 13 Integration tests
  • 23. 1 Your Apps will work together 2Continuously evolve codebase 3 No reinvention of the wheel 4Send only what’s needed 5 Get the dependencies graph 23 Testing contracts - benefits
  • 24. How to get started