SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Testing Scenarios
Lynn Langit
Types of Tests
from: "https://martinfowler.com/articles/microservice-testing"
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
updated from: "https://martinfowler.com/articles/microservice-testing"
Demo 1 - Unit tests: sayHello
Unit Test
import ballerina/test;
@test:Config
function testSayHelloTDD() {
string actual = sayHello(greetingAct);
test:assertEquals(actual,greetingExp,msg="string test failed");
}
Test Annotations
import ballerina/test;
@test:Config {
before: "beforeTestBar",
after: "afterTestBar",
dependsOn: ["testFunctionPre1", "testFuncctionPre2"],
groups: ["group1"]
}
function testBar() {
// test logic for function bar()
}
More Test Annotations & Assertions
import ballerina/test;
@test:BeforeSuite {...} | @test:BeforeEach {...} | @test:AfterSuite
{...}
function testBar() {
// test logic for function bar()
test:assertEquals(actual,greetingExp,msg="string test failed");
test:assertTrue(value,msg="Assert True failed");
test:assertFail("Expected an exception");
}
Running Tests
ballerina init
ballerina test [packageName] | [fileName.bal]
--list-groups tests
--groups group_a tests
--disable-groups group_b tests
--config myConf.conf
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
updated from: "https://martinfowler.com/articles/microservice-testing"
caller hello
GET
Hello World
Demo 2 - Service tests: Ballerina Service
Unit Test with Mock
@test:Mock { packageName: ".", functionName: "intAdd" }
function mockIntAdd(int a, int b)returns int)... { return (a - b); }
@test:Config
function testIntAdd() {
int answer = 0;
answer = intAdd(5, 3);
test:assertEquals(actual,2,msg="mock failed");
}
function intAdd(int a, int b)returns int)... { return (a + b); }
Service Test Setup
function startService(){
serviceStarted=test:startServices("hello-service");
}
@test:Config { before: "startService",after: "stopService" }
function testFunc() {
//...
}
function stopService() {
test:stopServices("hello-service");
}
Service Test Body
@test:Config { before: "startService",after: "stopService" }
function testFunc() {
endpoint http:Client httpEndpoint { url: "http://localhost:9090" };
test:assertTrue(serviceStarted, msg = "Unable to start the service");
...
match response {
...
test:assertEquals(res, response1);
}
error err => test:assertFail(msg = "Failed to call the endpoint:");
}
}
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
updated from: "https://martinfowler.com/articles/microservice-testing"
caller hello
response
Simpson quotes
GET
quote
twitter
tweet (quote)
response
Demo 3 - Services (composition) Tests
Services Test Setup
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
updated from: "https://martinfowler.com/articles/microservice-testing"
Demo 4 - Deployment Tests
Service Deployment - Docker
import ballerinax/docker;
@docker:Config {
registry:"ballerina.guides.io",
name:"travel_agency_service",
tag:"v1.0"
}
@docker:Expose{}
# Auto Generated Dockerfile
FROM ballerina/ballerina:0.975.1
LABEL maintainer="dev@ballerina.io"
COPY travel_agency.balx
/home/ballerina
EXPOSE 9090
CMD ballerina run travel_agency.balx
OSS Tools for Testing Containers
Sysdig - Falco for k8
● Uses rules
● Alerts on drift
● Includes container best practices
● Highly configurable
Google - Container Structure Tests
● Unit Tests
○ for Docker Images
● Command Tests
○ verifies output of running a
command inside container
● File Existence Tests
○ verifies existence of file at a
location
● File Content Tests
○ verifies file contents
● Metadata Test
○ verifies container configuration
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
updated from: "https://martinfowler.com/articles/microservice-testing"
Modern Approaches to Testing Microservices
from "https://opensource.com/article/18/6/five-microservice-testing-strategies-startups"
Documentation First
AWS Testing
(own-account)
Full stack
in-a-box
(local)
Shared
Testing
Instance
Stubbed
services Lorem ipsum congue
tempus
Lorem ipsum
tempus
Lorem ipsum
congue tempus
Lorem
ipsum
tempus
Documentation First
AWS
own-account
Full stack
in-a-box
local
Shared
Testing
Instances
Stubbed
Services
Breaking Things on Purpose
○ Inject something harmful
○ in order to build immunity
○ Chaos engineering
○ "thoughtful, planned experiments
designed to reveal the weakness in our
systems"
○ Testing proactively
○ instead of waiting for an outage
○ "Engineering Chaos" = better name
image from: https://www.anshulpatel.in/post/chaos_engg_exprmnt_dsgn/
Microservice Testing Reality
Unit Tests
Test functions
Test methods
Test services
Integration Tests
Test interactions within groups
Test interactions between groups
Test interactions outside groups
Deployment Tests
Test Container Configuration
Test Container Management
Configuration
Test Endpoints
Observability
Events, logs and alerts
Test in Production
Engineering Chaos
Modern Tests
Test Documentation
Full stack in-a-box
AWS own-account
Stubbed Services
05
01
02 03
04
exercism.io
How to get involved
Learn more
Open source
Get support
http://ballerina.io
http://github.com/ballerina-platform/
Stack Overflow #ballerina tag
Practice http://exercism.io/tracks/ballerina

Contenu connexe

Tendances

Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512
Masayuki Igawa
 
Whatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deploymentWhatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deployment
Christian Schwede
 

Tendances (20)

Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan KustAndroid Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
 
Open stack qa and tempest
Open stack qa and tempestOpen stack qa and tempest
Open stack qa and tempest
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan KustInfinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
 
Adding unit tests to the database deployment pipeline
Adding unit tests to the database deployment pipelineAdding unit tests to the database deployment pipeline
Adding unit tests to the database deployment pipeline
 
Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on Jenkins
 
DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
 
Adding unit tests to the database deployment pipeline
Adding unit tests to the database deployment pipelineAdding unit tests to the database deployment pipeline
Adding unit tests to the database deployment pipeline
 
Adding unit tests with tSQLt to the database deployment pipeline
 Adding unit tests with tSQLt to the database deployment pipeline Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
 
Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2
 
Whatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deploymentWhatthestack using Tempest for testing your OpenStack deployment
Whatthestack using Tempest for testing your OpenStack deployment
 
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
Seven perilous pitfalls to avoid with Java | DevNation Tech TalkSeven perilous pitfalls to avoid with Java | DevNation Tech Talk
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test Pyramid
 
Load Testing with k6 framework
Load Testing with k6 frameworkLoad Testing with k6 framework
Load Testing with k6 framework
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
 
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
 

Similaire à Testing in Ballerina Language

Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
Chris Farrell
 

Similaire à Testing in Ballerina Language (20)

How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App Engine
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App Engine
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
JUnit5 and TestContainers
JUnit5 and TestContainersJUnit5 and TestContainers
JUnit5 and TestContainers
 
Turner js
Turner jsTurner js
Turner js
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
In-Cluster Continuous Testing Framework for Docker Containers
In-Cluster Continuous Testing Framework for Docker ContainersIn-Cluster Continuous Testing Framework for Docker Containers
In-Cluster Continuous Testing Framework for Docker Containers
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
UPC Testing talk 2
UPC Testing talk 2UPC Testing talk 2
UPC Testing talk 2
 
Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
 

Plus de Lynn Langit

Plus de Lynn Langit (20)

VariantSpark on AWS
VariantSpark on AWSVariantSpark on AWS
VariantSpark on AWS
 
Serverless Architectures
Serverless ArchitecturesServerless Architectures
Serverless Architectures
 
10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids Programming10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids Programming
 
Blastn plus jupyter on Docker
Blastn plus jupyter on DockerBlastn plus jupyter on Docker
Blastn plus jupyter on Docker
 
Teaching Kids to create Alexa Skills
Teaching Kids to create Alexa SkillsTeaching Kids to create Alexa Skills
Teaching Kids to create Alexa Skills
 
Practical cloud
Practical cloudPractical cloud
Practical cloud
 
Understanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examplesUnderstanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examples
 
Genome-scale Big Data Pipelines
Genome-scale Big Data PipelinesGenome-scale Big Data Pipelines
Genome-scale Big Data Pipelines
 
Teaching Kids Programming
Teaching Kids ProgrammingTeaching Kids Programming
Teaching Kids Programming
 
Practical Cloud
Practical CloudPractical Cloud
Practical Cloud
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 
Genomic Scale Big Data Pipelines
Genomic Scale Big Data PipelinesGenomic Scale Big Data Pipelines
Genomic Scale Big Data Pipelines
 
VariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomicsVariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomics
 
Bioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWSBioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWS
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 
Beyond Relational
Beyond RelationalBeyond Relational
Beyond Relational
 
New AWS Services for Bioinformatics
New AWS Services for BioinformaticsNew AWS Services for Bioinformatics
New AWS Services for Bioinformatics
 
Google Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline PatternsGoogle Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline Patterns
 
Scaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud PlatformScaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud Platform
 
SQL Server on Google Cloud Platform
SQL Server on Google Cloud PlatformSQL Server on Google Cloud Platform
SQL Server on Google Cloud Platform
 

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)

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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
+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...
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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...
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 

Testing in Ballerina Language

  • 2. Types of Tests from: "https://martinfowler.com/articles/microservice-testing"
  • 3. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  • 4. Demo 1 - Unit tests: sayHello
  • 5. Unit Test import ballerina/test; @test:Config function testSayHelloTDD() { string actual = sayHello(greetingAct); test:assertEquals(actual,greetingExp,msg="string test failed"); }
  • 6. Test Annotations import ballerina/test; @test:Config { before: "beforeTestBar", after: "afterTestBar", dependsOn: ["testFunctionPre1", "testFuncctionPre2"], groups: ["group1"] } function testBar() { // test logic for function bar() }
  • 7. More Test Annotations & Assertions import ballerina/test; @test:BeforeSuite {...} | @test:BeforeEach {...} | @test:AfterSuite {...} function testBar() { // test logic for function bar() test:assertEquals(actual,greetingExp,msg="string test failed"); test:assertTrue(value,msg="Assert True failed"); test:assertFail("Expected an exception"); }
  • 8. Running Tests ballerina init ballerina test [packageName] | [fileName.bal] --list-groups tests --groups group_a tests --disable-groups group_b tests --config myConf.conf
  • 9. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  • 11. Demo 2 - Service tests: Ballerina Service
  • 12. Unit Test with Mock @test:Mock { packageName: ".", functionName: "intAdd" } function mockIntAdd(int a, int b)returns int)... { return (a - b); } @test:Config function testIntAdd() { int answer = 0; answer = intAdd(5, 3); test:assertEquals(actual,2,msg="mock failed"); } function intAdd(int a, int b)returns int)... { return (a + b); }
  • 13. Service Test Setup function startService(){ serviceStarted=test:startServices("hello-service"); } @test:Config { before: "startService",after: "stopService" } function testFunc() { //... } function stopService() { test:stopServices("hello-service"); }
  • 14. Service Test Body @test:Config { before: "startService",after: "stopService" } function testFunc() { endpoint http:Client httpEndpoint { url: "http://localhost:9090" }; test:assertTrue(serviceStarted, msg = "Unable to start the service"); ... match response { ... test:assertEquals(res, response1); } error err => test:assertFail(msg = "Failed to call the endpoint:"); } }
  • 15. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  • 17. Demo 3 - Services (composition) Tests
  • 19. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  • 20. Demo 4 - Deployment Tests
  • 21. Service Deployment - Docker import ballerinax/docker; @docker:Config { registry:"ballerina.guides.io", name:"travel_agency_service", tag:"v1.0" } @docker:Expose{} # Auto Generated Dockerfile FROM ballerina/ballerina:0.975.1 LABEL maintainer="dev@ballerina.io" COPY travel_agency.balx /home/ballerina EXPOSE 9090 CMD ballerina run travel_agency.balx
  • 22. OSS Tools for Testing Containers Sysdig - Falco for k8 ● Uses rules ● Alerts on drift ● Includes container best practices ● Highly configurable Google - Container Structure Tests ● Unit Tests ○ for Docker Images ● Command Tests ○ verifies output of running a command inside container ● File Existence Tests ○ verifies existence of file at a location ● File Content Tests ○ verifies file contents ● Metadata Test ○ verifies container configuration
  • 23. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  • 24. Modern Approaches to Testing Microservices from "https://opensource.com/article/18/6/five-microservice-testing-strategies-startups" Documentation First AWS Testing (own-account) Full stack in-a-box (local) Shared Testing Instance Stubbed services Lorem ipsum congue tempus Lorem ipsum tempus Lorem ipsum congue tempus Lorem ipsum tempus Documentation First AWS own-account Full stack in-a-box local Shared Testing Instances Stubbed Services
  • 25. Breaking Things on Purpose ○ Inject something harmful ○ in order to build immunity ○ Chaos engineering ○ "thoughtful, planned experiments designed to reveal the weakness in our systems" ○ Testing proactively ○ instead of waiting for an outage ○ "Engineering Chaos" = better name image from: https://www.anshulpatel.in/post/chaos_engg_exprmnt_dsgn/
  • 26.
  • 27. Microservice Testing Reality Unit Tests Test functions Test methods Test services Integration Tests Test interactions within groups Test interactions between groups Test interactions outside groups Deployment Tests Test Container Configuration Test Container Management Configuration Test Endpoints Observability Events, logs and alerts Test in Production Engineering Chaos Modern Tests Test Documentation Full stack in-a-box AWS own-account Stubbed Services 05 01 02 03 04
  • 29. How to get involved Learn more Open source Get support http://ballerina.io http://github.com/ballerina-platform/ Stack Overflow #ballerina tag Practice http://exercism.io/tracks/ballerina