Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
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
u...
Demo 1 - Unit tests: sayHello
Unit Test
import ballerina/test;
@test:Config
function testSayHelloTDD() {
string actual = sayHello(greetingAct);
test:ass...
Test Annotations
import ballerina/test;
@test:Config {
before: "beforeTestBar",
after: "afterTestBar",
dependsOn: ["testFu...
More Test Annotations & Assertions
import ballerina/test;
@test:BeforeSuite {...} | @test:BeforeEach {...} | @test:AfterSu...
Running Tests
ballerina init
ballerina test [packageName] | [fileName.bal]
--list-groups tests
--groups group_a tests
--di...
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
u...
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)....
Service Test Setup
function startService(){
serviceStarted=test:startServices("hello-service");
}
@test:Config { before: "...
Service Test Body
@test:Config { before: "startService",after: "stopService" }
function testFunc() {
endpoint http:Client ...
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
u...
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
u...
Demo 4 - Deployment Tests
Service Deployment - Docker
import ballerinax/docker;
@docker:Config {
registry:"ballerina.guides.io",
name:"travel_agency...
OSS Tools for Testing Containers
Sysdig - Falco for k8
● Uses rules
● Alerts on drift
● Includes container best practices
...
Testing Microservices
Function/ Method
Service REST
Services Package
Deploy Kubernetes
End-to-endLogs
Unit
Observability
u...
Modern Approaches to Testing Microservices
from "https://opensource.com/article/18/6/five-microservice-testing-strategies-...
Breaking Things on Purpose
○ Inject something harmful
○ in order to build immunity
○ Chaos engineering
○ "thoughtful, plan...
Microservice Testing Reality
Unit Tests
Test functions
Test methods
Test services
Integration Tests
Test interactions with...
exercism.io
How to get involved
Learn more
Open source
Get support
http://ballerina.io
http://github.com/ballerina-platform/
Stack Ove...
Testing in Ballerina Language
Próxima SlideShare
Cargando en…5
×

Testing in Ballerina Language

272 visualizaciones

Publicado el

testing in Ballerina Language

Publicado en: Tecnología
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Testing in Ballerina Language

  1. 1. Testing Scenarios Lynn Langit
  2. 2. Types of Tests from: "https://martinfowler.com/articles/microservice-testing"
  3. 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. 4. Demo 1 - Unit tests: sayHello
  5. 5. Unit Test import ballerina/test; @test:Config function testSayHelloTDD() { string actual = sayHello(greetingAct); test:assertEquals(actual,greetingExp,msg="string test failed"); }
  6. 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. 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. 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. 9. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  10. 10. caller hello GET Hello World
  11. 11. Demo 2 - Service tests: Ballerina Service
  12. 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. 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. 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. 15. Testing Microservices Function/ Method Service REST Services Package Deploy Kubernetes End-to-endLogs Unit Observability updated from: "https://martinfowler.com/articles/microservice-testing"
  16. 16. caller hello response Simpson quotes GET quote twitter tweet (quote) response
  17. 17. Demo 3 - Services (composition) Tests
  18. 18. Services Test Setup
  19. 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. 20. Demo 4 - Deployment Tests
  21. 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. 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. 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. 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. 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. 26. 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
  27. 27. exercism.io
  28. 28. 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

×