SlideShare a Scribd company logo
1 of 23
Peter Thomas | Architect | Intuit
@ptrthomas | @KarateDSL
Karate
Web Service API Testing Made Simple
Intuit Open Source
Released 09-Feb-2017
A DSL for writing web-service acceptance tests
Built on Cucumber | BDD syntax
Karate github.com/intuit/karate
3
Karate in the top 5 OSS API Testing Tools (TechBeacon)
Tool Inception Years
REST-assured 2010 7
Postman 2012 5
SoapUI 2005 12
JMeter 1998 19
Karate 2017 0.5
4
• Easier to Write
• Readable and Concise
• Faster Execution
• Better Assertions
• Integrates into existing CI / CD
API-tests with Karate
Developer
Productivity
Maintain-
ability
Quality
5
Many teams use Java for writing HTTP-API regression tests.
Java is not the best language to manipulate JSON / XML.
Consequences:
• Over-dependence on Java objects for building and validating
data-payloads
• Object-equality checks done by hand, effort-intensive
• So tests end-up taking “short-cuts”, and don’t validate the full
response, coverage & quality suffers
• Proliferation of helper methods, code bloat & in-house layers
• Result: poor Dev Productivity & Maintainability
Current State of Web-API Testing
• DSL laser-focused on HTTP
• JSON and XML are “first-class”
citizens of the syntax
• Compare deeply-nested payloads in
a single step
• 3:1 Reduction in Lines of Code
• Tests are super-readable and
concise
• Testing is Easier & actually Fun
Karate’s Solve
6
Scenario: create and retrieve a cat
Given url 'http://myhost.com/v1/cats'
And request { name: 'Billie' }
When method post
Then status 201
And match response == { id: '#notnull', name: 'Billie' }
Given path response.id
When method get
Then status 200
Hello World
Intuitive DSL
for HTTP
Payload
assertion in one
line
Second HTTP
call using
response data
JSON is ‘native’
to the syntax
7
Java
vs
JSON
8
Validation examples: JsonPath & RegEx
Type Directive
Ignore / Exists #ignore | #null | #notnull
Primitive Type #boolean | #number | #string
Complex Type #array | #object
Special #uuid
RegEx #regex <regex string>
Predicate #? <expression>
9
JSON ‘templating’
Type Directive
Replace #(<expression>)
10
XML and XPath
11
Standard form In-line form
* match foo[0] == exact * match foo[0] == '#(exact)'
* match foo[0] contains partial * match foo[0] == '#(^partial)'
* match foo[0] !contains nope * match foo[0] == '#(!^nope)'
* match each foo == exact * match foo == '#[] exact'
* match each foo contains partial * match foo == '#[] ^partial'
* match each foo !contains nope * match foo == '#[] !^nope'
* match foo contains only reversed * match foo == '#(^^reversed)'
* match foo contains first * match foo == '#(^first)'
* match foo !contains others * match foo == '#(!^others)'
* assert foo.length == 2 * match foo == '#[2]'
Schema Validations
12
Comparison with REST-assured
http://tinyurl.com/karateraREST-assured Karate
Plain Text ❌ (needs compilation) ✅
Parallel Execution ? (partial) ✅
Data Driven Testing ❌ (needs TestNG etc.) ✅ (built-in)
Environment Switching ❌ ✅ (built-in)
Match full payload in one step ❌ ✅
Update JSON payload / object ❌ ✅
@Test public void
lotto_resource_returns_200_with_expected_id_and_winners() {
when().
get("/lotto/{id}", 5).
then().
statusCode(200).
body("lotto.lottoId", equalTo(5),
"lotto.winners.winnerId", containsOnly(23, 54));
Scenario: lotto resource returns 200 with expected id and winners
Given path ‘lotto’, 5
When method get
Then status 200
And match $.lotto.lottoId == 5
And match $.lotto.winners[*].winnerId contains only [23, 54]
given().
param("key1", "value1").
param("key2", "value2").
when().
get("/somewhere").
then().
body(containsString("OK"));
Given param key1 = ‘value1’
And param key2 = ‘value2’
And path ‘somewhere’
When method get
Then response contains ‘OK’
Detailed Comparison
13
14
Metrics – port of an open-source example
Reduction of lines of code from 431  67
Link: https://github.com/mwinteringham/api-framework/pull/3
15
Components
Karate DSL interpreter
(Cucumber “Step Definitions”)
HTTP Client Abstraction
JSON XML
JS
Engine
(Nashorn)
Karate ScriptJUnit / Test
NG
(Runner)
Java8JRE
HTTP/S calls
Cucumber-
JVM
Data / Assertions
match, get, set
Reports
Apache Jersey
Mock
Servlet
16
The “missing” Cucumber Features that Karate adds
Capability Cucumber Karate
Step Definitions built-in, no Java code needed ❌ ✅
Re-Use Feature files from other Features ❌ ✅
Dynamic Data-Driven Testing ❌ ✅
Parallel Test Execution and Reporting ❌ ✅
Option to run routines only once per Feature ❌ ✅
17
Example Report
18
• Scripts are plain-text, no compilation or IDE required
• REST as well as SOAP support
• Assert, manipulate, compare and re-use JSON / XML
• User defined functions (Java or JavaScript)
• Configuration switching (e.g. dev | e2e | pre-prod)
• Simple ‘plug and play’ HTTP Header & Auth management
• Comprehensive HTTP support: SSL, Proxy, File-Upload
• JUnit XML reports compatible with all CI tools
• Speed - Parallel Execution of Tests
• Mock Servlet – test without starting a container
Karate Features
BDD
Full HTTP
CI / CD
Ready
Demos
Q & A
https://github.com/intuit/karate
@ptrthomas | @KarateDSL
Thank You !
Extra Slides
22
Karate UI (Alpha)
23
CI Report
(Jenkins)

More Related Content

What's hot

RSpec: What, How and Why
RSpec: What, How and WhyRSpec: What, How and Why
RSpec: What, How and WhyRatan Sebastian
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST AssuredBas Dijkstra
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1Wolfram Arnold
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD WorkshopWolfram Arnold
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsBDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsPatrick Viafore
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 

What's hot (20)

RSpec: What, How and Why
RSpec: What, How and WhyRSpec: What, How and Why
RSpec: What, How and Why
 
Karma - JS Test Runner
Karma - JS Test RunnerKarma - JS Test Runner
Karma - JS Test Runner
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Angular Unit Test
Angular Unit TestAngular Unit Test
Angular Unit Test
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
C# 6
C# 6C# 6
C# 6
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsBDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 

Similar to Karate - MoT Dallas 26-Oct-2017

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiRan Mizrahi
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You TestSchalk Cronjé
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113SOAT
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST serviceWO Community
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol BuffersMatt O'Keefe
 
Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications Hector Correa
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionSchalk Cronjé
 
Code Quality Practice and Tools
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and ToolsBob Paulin
 
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Jagadish Prasath
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBRob Tweed
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Eric Phan
 
Tests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularTests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularPaulo Cesar Ortins Brito
 
Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]JavaScript Meetup HCMC
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock FrameworkEugene Dvorkin
 
Dev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_testDev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_testMasanori Kato
 

Similar to Karate - MoT Dallas 26-Oct-2017 (20)

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran Mizrahi
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You Test
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST service
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
 
Code Quality Practice and Tools
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and Tools
 
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014
 
03 form-data
03 form-data03 form-data
03 form-data
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Tests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularTests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and Testacular
 
Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Dev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_testDev fest kyoto_2021-flutter_test
Dev fest kyoto_2021-flutter_test
 

Recently uploaded

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Recently uploaded (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Karate - MoT Dallas 26-Oct-2017

  • 1. Peter Thomas | Architect | Intuit @ptrthomas | @KarateDSL Karate Web Service API Testing Made Simple
  • 2. Intuit Open Source Released 09-Feb-2017 A DSL for writing web-service acceptance tests Built on Cucumber | BDD syntax Karate github.com/intuit/karate
  • 3. 3 Karate in the top 5 OSS API Testing Tools (TechBeacon) Tool Inception Years REST-assured 2010 7 Postman 2012 5 SoapUI 2005 12 JMeter 1998 19 Karate 2017 0.5
  • 4. 4 • Easier to Write • Readable and Concise • Faster Execution • Better Assertions • Integrates into existing CI / CD API-tests with Karate Developer Productivity Maintain- ability Quality
  • 5. 5 Many teams use Java for writing HTTP-API regression tests. Java is not the best language to manipulate JSON / XML. Consequences: • Over-dependence on Java objects for building and validating data-payloads • Object-equality checks done by hand, effort-intensive • So tests end-up taking “short-cuts”, and don’t validate the full response, coverage & quality suffers • Proliferation of helper methods, code bloat & in-house layers • Result: poor Dev Productivity & Maintainability Current State of Web-API Testing • DSL laser-focused on HTTP • JSON and XML are “first-class” citizens of the syntax • Compare deeply-nested payloads in a single step • 3:1 Reduction in Lines of Code • Tests are super-readable and concise • Testing is Easier & actually Fun Karate’s Solve
  • 6. 6 Scenario: create and retrieve a cat Given url 'http://myhost.com/v1/cats' And request { name: 'Billie' } When method post Then status 201 And match response == { id: '#notnull', name: 'Billie' } Given path response.id When method get Then status 200 Hello World Intuitive DSL for HTTP Payload assertion in one line Second HTTP call using response data JSON is ‘native’ to the syntax
  • 8. 8 Validation examples: JsonPath & RegEx Type Directive Ignore / Exists #ignore | #null | #notnull Primitive Type #boolean | #number | #string Complex Type #array | #object Special #uuid RegEx #regex <regex string> Predicate #? <expression>
  • 11. 11 Standard form In-line form * match foo[0] == exact * match foo[0] == '#(exact)' * match foo[0] contains partial * match foo[0] == '#(^partial)' * match foo[0] !contains nope * match foo[0] == '#(!^nope)' * match each foo == exact * match foo == '#[] exact' * match each foo contains partial * match foo == '#[] ^partial' * match each foo !contains nope * match foo == '#[] !^nope' * match foo contains only reversed * match foo == '#(^^reversed)' * match foo contains first * match foo == '#(^first)' * match foo !contains others * match foo == '#(!^others)' * assert foo.length == 2 * match foo == '#[2]' Schema Validations
  • 12. 12 Comparison with REST-assured http://tinyurl.com/karateraREST-assured Karate Plain Text ❌ (needs compilation) ✅ Parallel Execution ? (partial) ✅ Data Driven Testing ❌ (needs TestNG etc.) ✅ (built-in) Environment Switching ❌ ✅ (built-in) Match full payload in one step ❌ ✅ Update JSON payload / object ❌ ✅ @Test public void lotto_resource_returns_200_with_expected_id_and_winners() { when(). get("/lotto/{id}", 5). then(). statusCode(200). body("lotto.lottoId", equalTo(5), "lotto.winners.winnerId", containsOnly(23, 54)); Scenario: lotto resource returns 200 with expected id and winners Given path ‘lotto’, 5 When method get Then status 200 And match $.lotto.lottoId == 5 And match $.lotto.winners[*].winnerId contains only [23, 54] given(). param("key1", "value1"). param("key2", "value2"). when(). get("/somewhere"). then(). body(containsString("OK")); Given param key1 = ‘value1’ And param key2 = ‘value2’ And path ‘somewhere’ When method get Then response contains ‘OK’ Detailed Comparison
  • 13. 13
  • 14. 14 Metrics – port of an open-source example Reduction of lines of code from 431  67 Link: https://github.com/mwinteringham/api-framework/pull/3
  • 15. 15 Components Karate DSL interpreter (Cucumber “Step Definitions”) HTTP Client Abstraction JSON XML JS Engine (Nashorn) Karate ScriptJUnit / Test NG (Runner) Java8JRE HTTP/S calls Cucumber- JVM Data / Assertions match, get, set Reports Apache Jersey Mock Servlet
  • 16. 16 The “missing” Cucumber Features that Karate adds Capability Cucumber Karate Step Definitions built-in, no Java code needed ❌ ✅ Re-Use Feature files from other Features ❌ ✅ Dynamic Data-Driven Testing ❌ ✅ Parallel Test Execution and Reporting ❌ ✅ Option to run routines only once per Feature ❌ ✅
  • 18. 18 • Scripts are plain-text, no compilation or IDE required • REST as well as SOAP support • Assert, manipulate, compare and re-use JSON / XML • User defined functions (Java or JavaScript) • Configuration switching (e.g. dev | e2e | pre-prod) • Simple ‘plug and play’ HTTP Header & Auth management • Comprehensive HTTP support: SSL, Proxy, File-Upload • JUnit XML reports compatible with all CI tools • Speed - Parallel Execution of Tests • Mock Servlet – test without starting a container Karate Features BDD Full HTTP CI / CD Ready
  • 19. Demos

Editor's Notes

  1. Points to call out: No syntax “noise” JSON in-line, first-class citizen, no “escaping” Carefully crafted DSL for HTTP, the keywords are intuitive for someone who knows HTTP / REST Full-payload assertion in one line, and the ability to ignore dynamic server-side generated values at the same time.
  2. This shows how many lines of Java code are required for what is a “one-liner” in Karate. It also makes clear how easy it is to express data in JSON. The “impedance mismatch” between Java and JSON is clear. This is one of the reasons people find JS easier to work with and why NodeJS became so popular.
  3. Link to the detailed comparison (living) document: http://tinyurl.com/karatera Link to twitter thread where the creator of REST-assured weighed in: https://twitter.com/johanhaleby/status/846412707364552705
  4. Karate’s closest competitor is REST-Assured. This is a side-by-side comparison of a test in REST-Assured (plus TestNG) after porting to Karate. The example shows off Karate’s data-driven testing capability. Again, the readability and lack of “noise” stands out. RestAssured: http://bit.ly/2kGxiU0 Karate: https://gist.github.com/ptrthomas/0f5c00582b345a74d20261fb346225d0
  5. Things to call out: - re-use of Cucumber for syntax and unit-test / report integration - pluggable “future-proof” HTTP client abstraction Nashorn is the “secret sauce” that bridges the world of Java and JS and allows for easy user-defined functions & pluggability, without the need to re-compile any code JSON and XML are “first class” citizens with “equal rights”