Automatic Generation of Test Cases for REST
APIs: a Specification-Based Approach
Hamza Ed-douibi, Javier L. Cánovas Izquierdo, Jordi Cabot
unsplash-chuttersnap
flickr/clark-tibbs
Motivation
API-Driven World
API-Driven World
API-Driven World
API-Driven World
API-Driven World
unsplash-rawpixel
Leveraging OpenAPI for testing REST APIs
Leveraging OpenAPI for testing REST APIs
Leveraging OpenAPI for testing REST APIs
OpenAPI Metamodel
OpenAPI Model
Leveraging OpenAPI for testing REST APIs
TestSuite Metamodel
Our Approach
• Straightforward from the OpenAPI Metamodel
• Special attention to JSON references
Model Extraction
Our Approach
• Simple parameter (examples, default values, enums)
• Dummy parameter
• Complex parameter (response of an operation)
Inference rules
Our Approach
Generation Rules
GR 1. Nominal test case GR 2. Faulty test case
Generation Rules
GR 1. Nominal test case GR 2. Faulty test case
Faulty cases
• Required missing
• Wrong datatypes
• Violated constraints
Our Approach
Our Approach
https://github.com/SOM-Research/test-generator
unsplash-Hello I'm Nick
Validation
Validation
RQ1
What is the coverage level of the generated test
cases?
RQ2
What are the main failing points in the definitions
and implementation of real world REST APIs?
Validation
RQ1
What is the coverage level of the generated test
cases?
RQ2
What are the main failing points in the definitions
and implementation of real world REST APIs?
Filtering Criteria A ― Free, open and available APIs which provide access to data models
Validation
RQ1
What is the coverage level of the generated test
cases?
RQ2
What are the main failing points in the definitions
and implementation of real world REST APIs?
Filtering Criteria A ― Free, open and available APIs which provide access to data models
Filtering Criteria B ― Remove incorrect or invalid OpenAPI definitions
Validation
RQ1
What is the coverage level of the generated test
cases?
RQ2
What are the main failing points in the definitions
and implementation of real world REST APIs?
ELEMENTS COUNT
COVERAGE COVERAGE(%)
ALL NOMINAL FAULTY ALL NOMINAL FAULTY
OPERATIONS 367 320 303 233 87% 82% 63%
PARAMETERS 949 595 485 476 62% 51% 50%
ENDPOINTS 356 289 81%
DEFINITIONS 313 239 76%
Validation
RQ1
What is the coverage level of the generated test
cases?
RQ2
What are the main failing points in the definitions
and implementation of real world REST APIs?
ELEMENTS COUNT
COVERAGE COVERAGE(%)
ALL NOMINAL FAULTY ALL NOMINAL FAULTY
OPERATIONS 367 320 303 233 87% 82% 63%
PARAMETERS 949 595 485 476 62% 51% 50%
ENDPOINTS 356 289 81%
DEFINITIONS 313 239 76%
TOTAL
NOMINAL TEST CASES FAULTY TEST CASES
4XX/500 SCHEMA 500 2XX
NUMBER OF APIS 37 9 11 11 20
40% 25% 30% 30% 55%
Conclusion
• Model-driven approach to automate
REST API testing based on Open API
• Plug-in implementing the approach
• Coverage over 75%
What we have shown
What we want to do next
Increase coverage levels
Support for OpenAPI v3.0
unsplash-Vek Labs
Except where otherwise noted, content on this presentation is licensed under a Creative Commons Attribution 4.0 International license.
Thanks!
Javier L. Cánovas Izquierdo
jcanovasi@uoc.edu
@jlcanovas
Hamza Ed-douibi
hed-douibi@uoc.edu
@mazamiz
Jordi Cabot
jordi.cabot@icrea.cat
@softmodeling
https://github.com/SOM-Research/test-generator

Automatic Generation of Test Cases for REST APIs: a Specification-Based Approach