RESTful APIs (or REST APIs for short) represent a mainstream approach to design and develop web APIs using the REpresentational State Transfer architectural style. Black-box testing, which assumes only the access to the system under test with a specific interface, is the only viable option when white-box testing is impracticable. This is the case for REST APIs: their source code is usually not (or just partially) available, or a white-box analysis across many dynamically allocated distributed components (typical of a microservices architecture) is computationally challenging. This paper presents RESTTESTGEN, a novel black-box approach to automatically generate test cases for REST APIs, based on their interface definition (an OpenAPI specification). Input values and requests are generated for each operation of the API under test with the twofold objective of testing nominal execution scenarios and error scenarios. Two distinct oracles are deployed to detect when test cases reveal implementation defects. While this approach is mainly targeting the research community, it is also of interest to developers because, as a black-box approach, it is universally applicable across different programming languages, or in the case external (compiled only) libraries are used in a REST API. The validation of our approach has been performed on more than 100 of realworld REST APIs, highlighting the effectiveness of the approach in revealing actual faults in already deployed services.
K E Y W O R D S automatic test case generation, black-box testing, REST APIs, test oracle
| INTRODUCTIONREST APIs are the de-facto standard to implement and grant remote access to web APIs. They are so largely accepted and adopted that the Berlin Group Initiative 1 elaborated a standard based on REST APIs for unifying the European Banking APIs. This initiative was meant to address the PSD2 European Union directive 2 that requested banks to open their customer data to authorized third-party service providers. Moreover, reference implementations of PSD2 compliant banking APIs are mostly available in the form of REST APIs. 3 REST APIs are often components of micro-services architectures [1], according to which, each component should be small and assigned just one (or very few) responsibilities, resulting in a high number of simple components. Distinct components are usually deployed in different containers that can be dynamically allocated and deallocated, possibly across different hosts (for load balancing). 1 https://www.berlin-group.org/ 2 https://ec.europa.eu/info/law/payment-services-psd-2-directive-eu-2015-2366_en 3 https://www.openbankproject.com/