SlideShare a Scribd company logo
APACHE SLING & FRIENDS TECH MEETUP
10-12 SEPTEMBER 2018
Karate, the black belt of HTTP API testing?

Bertrand Delacretaz :: @bdelacretaz :: grep.codeconsult.ch

Principal Scientist, Adobe Basel

Sling PMC Member, Member of the Board of Directors, Apache Software Foundation

slides revision 2018-09-11 - images are from Adobe Stock unless specified - portrait of myself here by Stefan Wieland, thanks!
Example code at

https://tinyurl.com/potsdam2018
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Karate?
https://github.com/intuit/karate
Efficient (and fun?) way of testing
HTTP services.
Created by Peter Thomas of Intuit.
V0.1.2 in February 2017
Current 0.8.0, moving away from
Cucumber
Example code at

https://tinyurl.com/potsdam2018 !
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Great docs & demos!
Excerpts from https://github.com/intuit/karate
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
VERY readable tests - black belt!
Example from https://github.com/intuit/karate
“Laser focused on making things as simple as possible”
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
HTTP testing in a world of services…
HTTP
service

API
Clients 

(usually machines)
Opaque Services
THIS is the “sacred boundary” that needs to be

VERY SERIOUSLY tested and documented.
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Karate tests as HTTP API reference documentation?
A great complement to

overview + concepts docs !
Testing Apache Sling with Karate
and demonstrating major Karate features
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Test Feature: basic structure
<- Tags for test selection
<- Tests are “features”
<- Background section for setup
<- Call javascript or other features
<- Use Java code to compute

unique test paths
<- We’re ready to run Scenarios
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Sling PostServlet Scenario
CAN U RD THS ?
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Define JSON structures, verify (match) responses
Testing the “import” operation of
the SlingPostServlet
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Uploading an image
Schema-like
matching, see
next slide
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Schema-like matching
Used in:
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Matching the image itself!
“Laser focused on making things as simple as possible”
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
It’s not much code!
# The actual tests
src/test/java/sling/postservlet/importContent.feature
src/test/java/sling/postservlet/createContent.feature
src/test/java/sling/setup/initialContent.feature
src/test/java/sling/filestorage/uploadImage.feature
# JUnit tests "proxy"
src/test/java/sling/SlingTest.java (0 ALOC)
# Gatling performance tests "proxy"
src/test/scala/sling/PostServletSimulation.scala (~30 ALOC)
# Test utilities (all small)
src/test/java/util/cleanup-paths.js
src/test/java/util/basic-auth-header.js
src/test/java/util/sling-ready.feature
src/test/java/util/cleanup-path.feature
src/test/java/logBaseURL.js
# Test content
src/test/java/images/testimage.jpg
# Tests configuration
src/test/java/karate-config.js
src/test/java/logback-test.xml
Interlude: Running the Tests

aka “live demo”
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Running Karate tests
Using Maven via trivial JUnit proxy tests, selected by tags:
HTML test reports with debug info,

Gatling performance reports
Karate UI, basic
but useful.
More Fun & Useful Features

It’s not over yet
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Reuse Karate features for Gatling performance tests
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Scenario Outlines for data-driven testing
Validating initial content in
a default Sling instance
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Test Doubles: mock (main or auxiliary) services
Scenarios for
mocking HTTP
services,
similar syntax.
https://github.com/bdelacretaz/karate-mini-mocks
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018
Not much code for the Test Doubles either
# Mocked server + tests
src/test/java/server/server.feature
src/test/java/client/client.feature
# JUnit test "proxies"
src/test/java/server/TestBase.java
src/test/java/client/ClientTest.java
# Tests configuration
src/test/java/logback-test.xml
src/test/java/karate-config.js
Coda

Now it’s over. Almost.
Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - @bdelacretaz - adaptTo() 2018
Poweful, efficient, fun
and READABLE tests!
Open for contributions
Good enough to
document HTTP APIs?
Example code at

https://tinyurl.com/potsdam2018 !
https://github.com/intuit/karate

More Related Content

PDF
Karate - powerful and simple framework for REST API automation testing
PPTX
Karate DSL
PDF
Getting started with karate dsl
PPTX
API Test Automation Using Karate (Anil Kumar Moka)
PPTX
Karate for Complex Web-Service API Testing by Peter Thomas
PPTX
BDD Approach with Karate Framework in Service Tests
PPTX
RESTful API Testing using Postman, Newman, and Jenkins
PDF
Karate - Web-Service API Testing Made Simple
Karate - powerful and simple framework for REST API automation testing
Karate DSL
Getting started with karate dsl
API Test Automation Using Karate (Anil Kumar Moka)
Karate for Complex Web-Service API Testing by Peter Thomas
BDD Approach with Karate Framework in Service Tests
RESTful API Testing using Postman, Newman, and Jenkins
Karate - Web-Service API Testing Made Simple

What's hot (20)

PDF
Spring Boot
PDF
Postman: An Introduction for Developers
PDF
Postman Webinar: Postman 101
PPT
Postman.ppt
DOCX
Api testing bible using postman
PPSX
API Test Automation
PDF
API Testing
PDF
JUnit & Mockito, first steps
PPTX
Api Testing
PDF
Swagger UI
PPTX
Test Design and Automation for REST API
PPTX
Unit Testing And Mocking
PDF
Postman 101 & Office Hours
PDF
Functional Tests Automation with Robot Framework
PPTX
Postman. From simple API test to end to end scenario
PPTX
Spring boot
PDF
Spring Boot
PPTX
Java 8 - Features Overview
PDF
Loadrunner vs Jmeter
PDF
MVVM with SwiftUI and Combine
Spring Boot
Postman: An Introduction for Developers
Postman Webinar: Postman 101
Postman.ppt
Api testing bible using postman
API Test Automation
API Testing
JUnit & Mockito, first steps
Api Testing
Swagger UI
Test Design and Automation for REST API
Unit Testing And Mocking
Postman 101 & Office Hours
Functional Tests Automation with Robot Framework
Postman. From simple API test to end to end scenario
Spring boot
Spring Boot
Java 8 - Features Overview
Loadrunner vs Jmeter
MVVM with SwiftUI and Combine
Ad

Similar to Karate, the black belt of HTTP API testing? (20)

PPTX
Karate - MoT Dallas 26-Oct-2017
PDF
Wax on, wax off
PPTX
API Testing with Open Source Code and Cucumber
PPTX
Testing RESTful web services with REST Assured
PDF
API Test Automation using Karate.pdf
PDF
Karate API Testing-Complete Guidance by Testrig
PPT
Brightcove presentation on Automated Testing
PDF
Flavours - Classic/Technical BDD
PDF
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
PDF
Automated acceptance test
PPTX
BDD for APIs
PPTX
GeeCon.cz - Integration Testing from the Trenches Rebooted
PPTX
Helpful Automation Techniques - Selenium Camp 2014
PPT
Automated Testing Of Web Applications Using XML
PPTX
Ns e commerce integration tests
PDF
Next-Level API Automation Testing Techniques – Part 1
PPTX
Structured Functional Automated Web Service Testing
PDF
World-Class Testing Development Pipeline for Android
PDF
Deep dive into SoapUI
PPTX
B4USolution_API-Testing
Karate - MoT Dallas 26-Oct-2017
Wax on, wax off
API Testing with Open Source Code and Cucumber
Testing RESTful web services with REST Assured
API Test Automation using Karate.pdf
Karate API Testing-Complete Guidance by Testrig
Brightcove presentation on Automated Testing
Flavours - Classic/Technical BDD
[WSO2 API Day Chicago 2019] Sustainable Competitive Advantage
Automated acceptance test
BDD for APIs
GeeCon.cz - Integration Testing from the Trenches Rebooted
Helpful Automation Techniques - Selenium Camp 2014
Automated Testing Of Web Applications Using XML
Ns e commerce integration tests
Next-Level API Automation Testing Techniques – Part 1
Structured Functional Automated Web Service Testing
World-Class Testing Development Pipeline for Android
Deep dive into SoapUI
B4USolution_API-Testing
Ad

More from Bertrand Delacretaz (20)

PDF
VanillaJS & the Web Platform, a match made in heaven?
PDF
Surviving large online communities with conciseness and clarity
PDF
Repoinit: a mini-language for content repository initialization
PDF
The Moving House Model, adhocracy and remote collaboration
PDF
GraphQL in Apache Sling - but isn't it the opposite of REST?
PDF
Open Source Changes the World!
PDF
How to convince your left brain (or manager) to follow the Open Source path t...
PDF
L'Open Source change le Monde - BlendWebMix 2019
PDF
Shared Neurons - the Secret Sauce of Open Source communities?
PDF
Sling and Serverless, Best Friends Forever?
PDF
Serverless - introduction et perspectives concrètes
PDF
State of the Feather - ApacheCon North America 2018
PDF
Open Source at Scale: the Apache Software Foundation (2018)
PDF
They don't understand me! Tales from the multi-cultural trenches
PDF
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
PDF
Project and Community Services the Apache Way
PDF
La Fondation Apache - keynote au Paris Open Source Summit 2017
PDF
Asynchronous Decision Making - FOSS Backstage 2017
PDF
Building an Apache Sling Rendering Farm
PDF
Who needs meetings? Asynchronous Decision Making to the rescue
VanillaJS & the Web Platform, a match made in heaven?
Surviving large online communities with conciseness and clarity
Repoinit: a mini-language for content repository initialization
The Moving House Model, adhocracy and remote collaboration
GraphQL in Apache Sling - but isn't it the opposite of REST?
Open Source Changes the World!
How to convince your left brain (or manager) to follow the Open Source path t...
L'Open Source change le Monde - BlendWebMix 2019
Shared Neurons - the Secret Sauce of Open Source communities?
Sling and Serverless, Best Friends Forever?
Serverless - introduction et perspectives concrètes
State of the Feather - ApacheCon North America 2018
Open Source at Scale: the Apache Software Foundation (2018)
They don't understand me! Tales from the multi-cultural trenches
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
Project and Community Services the Apache Way
La Fondation Apache - keynote au Paris Open Source Summit 2017
Asynchronous Decision Making - FOSS Backstage 2017
Building an Apache Sling Rendering Farm
Who needs meetings? Asynchronous Decision Making to the rescue

Recently uploaded (20)

PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
artificial intelligence overview of it and more
PPTX
Digital Literacy And Online Safety on internet
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
DOCX
Unit-3 cyber security network security of internet system
PPTX
Funds Management Learning Material for Beg
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
presentation_pfe-universite-molay-seltan.pptx
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Slides PDF The World Game (s) Eco Economic Epochs.pdf
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
artificial intelligence overview of it and more
Digital Literacy And Online Safety on internet
The Internet -By the Numbers, Sri Lanka Edition
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Unit-3 cyber security network security of internet system
Funds Management Learning Material for Beg
An introduction to the IFRS (ISSB) Stndards.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
Design_with_Watersergyerge45hrbgre4top (1).ppt
RPKI Status Update, presented by Makito Lay at IDNOG 10
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
introduction about ICD -10 & ICD-11 ppt.pptx

Karate, the black belt of HTTP API testing?

  • 1. APACHE SLING & FRIENDS TECH MEETUP 10-12 SEPTEMBER 2018 Karate, the black belt of HTTP API testing?
 Bertrand Delacretaz :: @bdelacretaz :: grep.codeconsult.ch
 Principal Scientist, Adobe Basel
 Sling PMC Member, Member of the Board of Directors, Apache Software Foundation
 slides revision 2018-09-11 - images are from Adobe Stock unless specified - portrait of myself here by Stefan Wieland, thanks! Example code at
 https://tinyurl.com/potsdam2018
  • 2. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Karate? https://github.com/intuit/karate Efficient (and fun?) way of testing HTTP services. Created by Peter Thomas of Intuit. V0.1.2 in February 2017 Current 0.8.0, moving away from Cucumber Example code at
 https://tinyurl.com/potsdam2018 !
  • 3. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Great docs & demos! Excerpts from https://github.com/intuit/karate
  • 4. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 VERY readable tests - black belt! Example from https://github.com/intuit/karate “Laser focused on making things as simple as possible”
  • 5. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 HTTP testing in a world of services… HTTP service
 API Clients 
 (usually machines) Opaque Services THIS is the “sacred boundary” that needs to be
 VERY SERIOUSLY tested and documented.
  • 6. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Karate tests as HTTP API reference documentation? A great complement to
 overview + concepts docs !
  • 7. Testing Apache Sling with Karate
and demonstrating major Karate features
  • 8. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Test Feature: basic structure <- Tags for test selection <- Tests are “features” <- Background section for setup <- Call javascript or other features <- Use Java code to compute
 unique test paths <- We’re ready to run Scenarios
  • 9. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Sling PostServlet Scenario CAN U RD THS ?
  • 10. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Define JSON structures, verify (match) responses Testing the “import” operation of the SlingPostServlet
  • 11. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Uploading an image Schema-like matching, see next slide
  • 12. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Schema-like matching Used in:
  • 13. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Matching the image itself! “Laser focused on making things as simple as possible”
  • 14. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 It’s not much code! # The actual tests src/test/java/sling/postservlet/importContent.feature src/test/java/sling/postservlet/createContent.feature src/test/java/sling/setup/initialContent.feature src/test/java/sling/filestorage/uploadImage.feature # JUnit tests "proxy" src/test/java/sling/SlingTest.java (0 ALOC) # Gatling performance tests "proxy" src/test/scala/sling/PostServletSimulation.scala (~30 ALOC) # Test utilities (all small) src/test/java/util/cleanup-paths.js src/test/java/util/basic-auth-header.js src/test/java/util/sling-ready.feature src/test/java/util/cleanup-path.feature src/test/java/logBaseURL.js # Test content src/test/java/images/testimage.jpg # Tests configuration src/test/java/karate-config.js src/test/java/logback-test.xml
  • 15. Interlude: Running the Tests
 aka “live demo”
  • 16. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Running Karate tests Using Maven via trivial JUnit proxy tests, selected by tags: HTML test reports with debug info,
 Gatling performance reports Karate UI, basic but useful.
  • 17. More Fun & Useful Features
 It’s not over yet
  • 18. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Reuse Karate features for Gatling performance tests
  • 19. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Scenario Outlines for data-driven testing Validating initial content in a default Sling instance
  • 20. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Test Doubles: mock (main or auxiliary) services Scenarios for mocking HTTP services, similar syntax. https://github.com/bdelacretaz/karate-mini-mocks
  • 21. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Not much code for the Test Doubles either # Mocked server + tests src/test/java/server/server.feature src/test/java/client/client.feature # JUnit test "proxies" src/test/java/server/TestBase.java src/test/java/client/ClientTest.java # Tests configuration src/test/java/logback-test.xml src/test/java/karate-config.js
  • 23. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - @bdelacretaz - adaptTo() 2018 Poweful, efficient, fun and READABLE tests! Open for contributions Good enough to document HTTP APIs? Example code at
 https://tinyurl.com/potsdam2018 ! https://github.com/intuit/karate