SlideShare a Scribd company logo
API testing with Open Source
Code libraries and Cucumber
Ole Lensmar – SmartBear
22
Short about “Shift-Left”
• Enterprise testing and QA is moving from late to
early phases in the development life-cycle
– QA -> Dev -> Design
• Tests are being expressed as code instead of using
visual tools (by both QA and Dev)
– Re-use of existing Test assets / scripts for different types of
tests
• Code-driven approach not just for functional testing
– Load/performance testing
– Security testing
– Mocking / Virtualization
33
Testing at API layer vs Unit tests
• API-layer testing = integration testing of
implementing classes/components
• Unit-testing frameworks often used to
”orchestrate”
– Junit / TestNG / Failsafe etc.
• Tests are managed together with implementing
code - using traditional SCM tools
• Tests are executed as part of existing builds
– Test running instance of API vs implementation
44
Code driven approach to API Testing
• HTTP clients
– Apache HTTPClient, OkHttp, Super-agent, etc.
• Generated clients
– Swagger Codegen, WSDL2Java, etc.
• Special purpose libraries
– REST-Assured (Java/Groovy)
– Chakram, (JS)
– ReadyApi4j (Java)
• Cucumber / BDD - many platforms/languages
55
Approach for comparison
• Simple scenario with single and chained REST
requests testing the SwaggerHub integration API
• Framework specific highlights
• All available on GitHub:
https://github.com/olensmar/apidays-apitesting
• All run with maven (“mvn test”) except javascript
sample
66
Apache HTTP-Client
• Widely used java client library for HTTP
• Exposes fluent API for building / executing
requests and reading responses
• Lacks built in support for JSON / XML parsing or
assertions
– Need to do this manually using Jackson/DOM/etc.
77
Generated clients
• Use code-generation tools to generate client from
API description
• Write tests using generated client
– Automate client generation as part of build
• Pros
– API changes can break tests
– Isolates from network layer – tests at functional level
• Cons
– Relies on correctness of client-generator
– Isolates from network layer – tests at functional level
88
REST-Assured
• Fluent Java API for testing REST APIs
• Support both JSON and XML content assertions
– Uses standalone JSONPath and Xpath implementations
• Built in support for multiple authentication types, XSRF,
etc.
• Very customizable at the network/http/marshalling layers
• http://rest-assured.io/
99
ReadyAPI4j
• Fluent Java API
– Leverages the SoapUI Testing engine
– REST, SOAP, Assertions, orchestration, etc.
• Internally compiles tests into “Test Recipes”
(json)
– Can be reused for performance/security testing in
SoapUI
• Execution either locally or remotely
– Local execution for ease of use (open source)
– Remote execution for access control, performance,
reporting, etc. (commercial)
1010
Maven/Java project
ReadyApi4j execution model
API Test
/src/test/java
ReadyApi4j API
Local Engine ReadyAPI
Testserver
API(s) under test
use
use
call
API calls
1111
Challenges with code-driven API testing
• Running against different environments
– Temporary environments (Docker can help)
– Actual environments
• Testing either with or without network
– Network is more realistic – more work to automate
• External dependencies may need to be mocked
– 3rd party APIs, databases, etc.
– For both functional and non-functional testing
• Simulate errors, response times, invalid responses, etc.
Cucumber for API testing
1313
Cucumber – “Executable Specifications”
• Heavily associated with Behavior Driven Development
• “Plain language” verbalization of requirements
– POs, Business Analysts, Developers, Testers, etc.
• For example
Given a user has logged in with valid credentials
When a deposit of 100 USD is made
Then the account balance increases by 100 USD
And the user gets a confirmation message
1414
Scenarios/Features written in “Gherkin”
• Given X
• When Y
• Then Z
• More keywords: And, Feature, Scenario,
Background, etc.
• Packaged into “feature files”
• Cucumber reads feature files and executes
corresponding “StepDefs” or “GlueCode”
1515
Automated Build / Test executions
Cucumber “execution pipeline”
Cucumber
Runner
StepDefs
Component /
System under test
1. Parse
2. Invoke
.feature files
Ant/Maven/Gra
dle/CLI/etc [@tag]
1616
Cucumber StepDefs
• Code that is executed by the cucumber
framework for each statement
• Must be implemented manually to support the
desired vocabulary
• Cucumber Java example -> code!
1717
Cucumber “styles”
• Declarative style
– Domain-specific vocabulary for describing the business
requirements
– Appeals to non-technical users
– High overhead in creation and maintenance
• Imperative style
– Generic vocabulary for describing requirements
– Appeals more to technical users
– Lower maintenance – but “Misses the point”
• Either requires implementation of StepDefs
1818
Declarative API Testing Example
Feature: SwaggerHub REST API
Scenario: Default API Listing
When a request to the API listing is made
Then a list of APIs should be returned within 500ms
Scenario: TestServer API Retrieval
Given an owner named smartbear
And an api named ready-api-testserver
And a version named 1.0.0
When a request to the API listing is made
Then an API definition should be returned within 500ms
1919
Imperative API Testing Example
Feature: Petstore API
Scenario: Find pet by status
Given the API running at http://petstore.swagger.io/v2
When a GET request to /pet/findByStatus is made
And the status parameter is test
And the Accepts header is application/json
Then a 200 response is returned within 50ms
2020
Imperative API Testing Example with Swagger
Feature: Petstore API
operationId gives
path and method
operation parameter
type not neededa defined response
2121
Managing Feature files and StepDefs
• Keep feature files together with source code
and/or in separate repository
• Use tagging feature of Cucumber to selectively
(re)run tests
• Use datasets for parameterization
– Inline or external
• Bundle StepDefs in separate library
– Automate execution
2222
ReadyApi4j - Cucumber for APIs
• Out-of-the box generic vocabulary for REST API Testing -
integrated Swagger support
• Extensible – built on Cucumber for Java
– Open-source on GitHub
– https://github.com/readyapi/testserver-cucumber
• Packaged as library or Docker image
– https://hub.docker.com/r/smartbear/cucumber4apis
• Uses ReadyApi4j as execution engine (either local or
remote)
2323
That’s it! – Questions?
• @olensmar
• https://github.com/olensmar/apidays-apitesting
• https://hc.apache.org
• http://rest-assured.io/
• http://dareid.github.io/chakram/
• http://frisbyjs.com/
• https://github.com/SmartBear/readyapi4j
• https://cucumber.io/
• https://github.com/readyapi/testserver-cucumber
• https://hub.docker.com/r/smartbear/cucumber4apis

More Related Content

PPTX
API Automation Testing Using RestAssured+Cucumber
PDF
Selenium with Cucumber
PPTX
API Testing Using REST Assured with TestNG
ODP
BDD with Cucumber
PPTX
Test Automation Framework with BDD and Cucumber
PPSX
API Test Automation
PPTX
BDD WITH CUCUMBER AND JAVA
PPTX
Jenkins Introduction
API Automation Testing Using RestAssured+Cucumber
Selenium with Cucumber
API Testing Using REST Assured with TestNG
BDD with Cucumber
Test Automation Framework with BDD and Cucumber
API Test Automation
BDD WITH CUCUMBER AND JAVA
Jenkins Introduction

What's hot (20)

PPTX
Cucumber BDD
PPTX
Cucumber presenation
PPTX
Rest assured
PDF
PDF
Postman: An Introduction for Developers
PPTX
Cucumber With Selenium
PDF
How to Automate API Testing
PPTX
Testing microservices with rest assured
PDF
Introduction to Selenium | Selenium Tutorial for Beginners | Selenium Trainin...
PPTX
Test in Rest. API testing with the help of Rest Assured.
PPTX
Selenium WebDriver training
PDF
Getting Started With Cypress
PPTX
Cypress Automation
PPT
Selenium Presentation at Engineering Colleges
PPTX
6 Ways to Measure the ROI of Automated Testing
PDF
Postman: An Introduction for Testers
PDF
API Testing
PPTX
Selenium
PDF
BDD & Cucumber
ODP
An Introduction To Jenkins
Cucumber BDD
Cucumber presenation
Rest assured
Postman: An Introduction for Developers
Cucumber With Selenium
How to Automate API Testing
Testing microservices with rest assured
Introduction to Selenium | Selenium Tutorial for Beginners | Selenium Trainin...
Test in Rest. API testing with the help of Rest Assured.
Selenium WebDriver training
Getting Started With Cypress
Cypress Automation
Selenium Presentation at Engineering Colleges
6 Ways to Measure the ROI of Automated Testing
Postman: An Introduction for Testers
API Testing
Selenium
BDD & Cucumber
An Introduction To Jenkins
Ad

Similar to API Testing with Open Source Code and Cucumber (20)

PDF
Aws Technical Day 2015 - Amazon API Gateway
PDF
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
PPTX
Structured Functional Automated Web Service Testing
PPTX
A basic introduction to API Testing & its importance.
PPTX
API testing - Japura.pptx
PPTX
Jakarta EE Test Strategies (2022)
PDF
PPTX
Testing Testing everywhere
PDF
API Check Overview - Rigor Monitoring
PPTX
Introduction to cypress in Angular (Chinese)
PPTX
AWS Summit Barcelona 2015 - Introducing Amazon API Gateway
PPTX
API City 2019 Presentation - Delivering Developer Tools at Scale: Microsoft A...
PDF
Kafka for Microservices – You absolutely need Avro Schemas! | Gerardo Gutierr...
PPTX
SOA Testing
PPT
Brightcove presentation on Automated Testing
PPTX
One to rule them all
PPTX
Helpful Automation Techniques - Selenium Camp 2014
PDF
Api security-testing
PPTX
What I Learned From Writing a Test Framework (And Why I May Never Write One A...
PDF
Designing your API Server for mobile apps
Aws Technical Day 2015 - Amazon API Gateway
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
Structured Functional Automated Web Service Testing
A basic introduction to API Testing & its importance.
API testing - Japura.pptx
Jakarta EE Test Strategies (2022)
Testing Testing everywhere
API Check Overview - Rigor Monitoring
Introduction to cypress in Angular (Chinese)
AWS Summit Barcelona 2015 - Introducing Amazon API Gateway
API City 2019 Presentation - Delivering Developer Tools at Scale: Microsoft A...
Kafka for Microservices – You absolutely need Avro Schemas! | Gerardo Gutierr...
SOA Testing
Brightcove presentation on Automated Testing
One to rule them all
Helpful Automation Techniques - Selenium Camp 2014
Api security-testing
What I Learned From Writing a Test Framework (And Why I May Never Write One A...
Designing your API Server for mobile apps
Ad

More from SmartBear (20)

PPTX
Enforcing Your Organization's API Design Standards with SwaggerHub
PPTX
Introducing OpenAPI Version 3.1
PPTX
IATA Open Air: How API Standardization Enables Innovation in the Airline Indu...
PPTX
The State of API 2020 Webinar – Exploring Trends, Tools & Takeaways to Drive ...
PPTX
How LISI Automotive Accelerated Application Delivery with SwaggerHub
PPTX
Standardising APIs: Powering the Platform Economy in Financial Services
PPTX
Getting Started with API Standardization in SwaggerHub
PPTX
Adopting a Design-First Approach to API Development with SwaggerHub
PPTX
Standardizing APIs Across Your Organization with Swagger and OAS | A SmartBea...
PPTX
Effective API Lifecycle Management
PDF
The API Lifecycle Series: Exploring Design-First and Code-First Approaches to...
PDF
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
PPTX
Artificial intelligence for faster and smarter software testing - Galway Mee...
PDF
Successfully Implementing BDD in an Agile World
PPTX
The Best Kept Secrets of Code Review | SmartBear Webinar
PPTX
How Capital One Scaled API Design to Deliver New Products Faster
PPTX
Testing Without a GUI Using TestComplete
PPTX
Hidden Treasure - TestComplete Script Extensions
PDF
How Bdd Can Save Agile
PPTX
API Automation and TDD to Implement Master Data Survivorship Rules
Enforcing Your Organization's API Design Standards with SwaggerHub
Introducing OpenAPI Version 3.1
IATA Open Air: How API Standardization Enables Innovation in the Airline Indu...
The State of API 2020 Webinar – Exploring Trends, Tools & Takeaways to Drive ...
How LISI Automotive Accelerated Application Delivery with SwaggerHub
Standardising APIs: Powering the Platform Economy in Financial Services
Getting Started with API Standardization in SwaggerHub
Adopting a Design-First Approach to API Development with SwaggerHub
Standardizing APIs Across Your Organization with Swagger and OAS | A SmartBea...
Effective API Lifecycle Management
The API Lifecycle Series: Exploring Design-First and Code-First Approaches to...
The API Lifecycle Series: Evolving API Development and Testing from Open Sour...
Artificial intelligence for faster and smarter software testing - Galway Mee...
Successfully Implementing BDD in an Agile World
The Best Kept Secrets of Code Review | SmartBear Webinar
How Capital One Scaled API Design to Deliver New Products Faster
Testing Without a GUI Using TestComplete
Hidden Treasure - TestComplete Script Extensions
How Bdd Can Save Agile
API Automation and TDD to Implement Master Data Survivorship Rules

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Diabetes mellitus diagnosis method based random forest with bat algorithm
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation

API Testing with Open Source Code and Cucumber

  • 1. API testing with Open Source Code libraries and Cucumber Ole Lensmar – SmartBear
  • 2. 22 Short about “Shift-Left” • Enterprise testing and QA is moving from late to early phases in the development life-cycle – QA -> Dev -> Design • Tests are being expressed as code instead of using visual tools (by both QA and Dev) – Re-use of existing Test assets / scripts for different types of tests • Code-driven approach not just for functional testing – Load/performance testing – Security testing – Mocking / Virtualization
  • 3. 33 Testing at API layer vs Unit tests • API-layer testing = integration testing of implementing classes/components • Unit-testing frameworks often used to ”orchestrate” – Junit / TestNG / Failsafe etc. • Tests are managed together with implementing code - using traditional SCM tools • Tests are executed as part of existing builds – Test running instance of API vs implementation
  • 4. 44 Code driven approach to API Testing • HTTP clients – Apache HTTPClient, OkHttp, Super-agent, etc. • Generated clients – Swagger Codegen, WSDL2Java, etc. • Special purpose libraries – REST-Assured (Java/Groovy) – Chakram, (JS) – ReadyApi4j (Java) • Cucumber / BDD - many platforms/languages
  • 5. 55 Approach for comparison • Simple scenario with single and chained REST requests testing the SwaggerHub integration API • Framework specific highlights • All available on GitHub: https://github.com/olensmar/apidays-apitesting • All run with maven (“mvn test”) except javascript sample
  • 6. 66 Apache HTTP-Client • Widely used java client library for HTTP • Exposes fluent API for building / executing requests and reading responses • Lacks built in support for JSON / XML parsing or assertions – Need to do this manually using Jackson/DOM/etc.
  • 7. 77 Generated clients • Use code-generation tools to generate client from API description • Write tests using generated client – Automate client generation as part of build • Pros – API changes can break tests – Isolates from network layer – tests at functional level • Cons – Relies on correctness of client-generator – Isolates from network layer – tests at functional level
  • 8. 88 REST-Assured • Fluent Java API for testing REST APIs • Support both JSON and XML content assertions – Uses standalone JSONPath and Xpath implementations • Built in support for multiple authentication types, XSRF, etc. • Very customizable at the network/http/marshalling layers • http://rest-assured.io/
  • 9. 99 ReadyAPI4j • Fluent Java API – Leverages the SoapUI Testing engine – REST, SOAP, Assertions, orchestration, etc. • Internally compiles tests into “Test Recipes” (json) – Can be reused for performance/security testing in SoapUI • Execution either locally or remotely – Local execution for ease of use (open source) – Remote execution for access control, performance, reporting, etc. (commercial)
  • 10. 1010 Maven/Java project ReadyApi4j execution model API Test /src/test/java ReadyApi4j API Local Engine ReadyAPI Testserver API(s) under test use use call API calls
  • 11. 1111 Challenges with code-driven API testing • Running against different environments – Temporary environments (Docker can help) – Actual environments • Testing either with or without network – Network is more realistic – more work to automate • External dependencies may need to be mocked – 3rd party APIs, databases, etc. – For both functional and non-functional testing • Simulate errors, response times, invalid responses, etc.
  • 12. Cucumber for API testing
  • 13. 1313 Cucumber – “Executable Specifications” • Heavily associated with Behavior Driven Development • “Plain language” verbalization of requirements – POs, Business Analysts, Developers, Testers, etc. • For example Given a user has logged in with valid credentials When a deposit of 100 USD is made Then the account balance increases by 100 USD And the user gets a confirmation message
  • 14. 1414 Scenarios/Features written in “Gherkin” • Given X • When Y • Then Z • More keywords: And, Feature, Scenario, Background, etc. • Packaged into “feature files” • Cucumber reads feature files and executes corresponding “StepDefs” or “GlueCode”
  • 15. 1515 Automated Build / Test executions Cucumber “execution pipeline” Cucumber Runner StepDefs Component / System under test 1. Parse 2. Invoke .feature files Ant/Maven/Gra dle/CLI/etc [@tag]
  • 16. 1616 Cucumber StepDefs • Code that is executed by the cucumber framework for each statement • Must be implemented manually to support the desired vocabulary • Cucumber Java example -> code!
  • 17. 1717 Cucumber “styles” • Declarative style – Domain-specific vocabulary for describing the business requirements – Appeals to non-technical users – High overhead in creation and maintenance • Imperative style – Generic vocabulary for describing requirements – Appeals more to technical users – Lower maintenance – but “Misses the point” • Either requires implementation of StepDefs
  • 18. 1818 Declarative API Testing Example Feature: SwaggerHub REST API Scenario: Default API Listing When a request to the API listing is made Then a list of APIs should be returned within 500ms Scenario: TestServer API Retrieval Given an owner named smartbear And an api named ready-api-testserver And a version named 1.0.0 When a request to the API listing is made Then an API definition should be returned within 500ms
  • 19. 1919 Imperative API Testing Example Feature: Petstore API Scenario: Find pet by status Given the API running at http://petstore.swagger.io/v2 When a GET request to /pet/findByStatus is made And the status parameter is test And the Accepts header is application/json Then a 200 response is returned within 50ms
  • 20. 2020 Imperative API Testing Example with Swagger Feature: Petstore API operationId gives path and method operation parameter type not neededa defined response
  • 21. 2121 Managing Feature files and StepDefs • Keep feature files together with source code and/or in separate repository • Use tagging feature of Cucumber to selectively (re)run tests • Use datasets for parameterization – Inline or external • Bundle StepDefs in separate library – Automate execution
  • 22. 2222 ReadyApi4j - Cucumber for APIs • Out-of-the box generic vocabulary for REST API Testing - integrated Swagger support • Extensible – built on Cucumber for Java – Open-source on GitHub – https://github.com/readyapi/testserver-cucumber • Packaged as library or Docker image – https://hub.docker.com/r/smartbear/cucumber4apis • Uses ReadyApi4j as execution engine (either local or remote)
  • 23. 2323 That’s it! – Questions? • @olensmar • https://github.com/olensmar/apidays-apitesting • https://hc.apache.org • http://rest-assured.io/ • http://dareid.github.io/chakram/ • http://frisbyjs.com/ • https://github.com/SmartBear/readyapi4j • https://cucumber.io/ • https://github.com/readyapi/testserver-cucumber • https://hub.docker.com/r/smartbear/cucumber4apis