Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Karate, the black belt of HTTP API testing?

759 views

Published on

Slides of my talk on the Karate testing tool at adaptTo() 2018, https://adapt.to/2018/en/schedule/karate-the-black-belt-of-http-api-testing.html

Published in: Internet
  • Be the first to comment

Karate, the black belt of HTTP API testing?

  1. 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. 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. 3. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Great docs & demos! Excerpts from https://github.com/intuit/karate
  4. 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. 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. 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. 7. Testing Apache Sling with Karate
and demonstrating major Karate features
  8. 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. 9. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Sling PostServlet Scenario CAN U RD THS ?
  10. 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. 11. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Uploading an image Schema-like matching, see next slide
  12. 12. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Schema-like matching Used in:
  13. 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. 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. 15. Interlude: Running the Tests
 aka “live demo”
  16. 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. 17. More Fun & Useful Features
 It’s not over yet
  18. 18. Karate, the black belt of HTTP API testing? - Bertrand Delacretaz - adaptTo() 2018 Reuse Karate features for Gatling performance tests
  19. 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. 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. 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
  22. 22. Coda
 Now it’s over. Almost.
  23. 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

×