Surprisingly, even though RESTful microservices are everywhere nowadays, open source tools for automated testing of such hardly exist.
How about tools which can consume the OpenAPI (Swagger) description of REST APIs and generate tests, including test data, based on this information? Such automated testing nirvana truly exists!
In this purely practical presentation, based on a recent deployment on a commercial project for my current client, Data In Motion Consulting GmbH (https://www.datainmotion.de/), I will show you how to implement an always in-sync, fully automated OpenAPI-described RESTful microservices testing solution with freely available open-source tools, including:
-
automated generation of REST API smoke test scripts, utilizing the OpenAPI (Swagger) spec and the K6 (https://k6.io/) OpenAPI generator (https://openapi-generator.tech/)
-
automated extraction of test data from examples specified in the OpenAPI (Swagger) spec, for a self-contained, ready-to-run REST API test script
-
adding new K6 OpenAPI generator test generation template for automated generation of REST API load tests, in addition to REST API smoke tests
-
adding support for automated OAuth 2.0 authentication of REST API calls
-
integrating into Jenkins CI/CD pipeline the automated generation of REST API tests as well as automated testing of REST APIs via generated test scripts
As you will see, the benefits of describing RESTful microservices with OpenAPI (Swagger) go way beyond living documentation. With freely available open-source tools, your REST APIs can all be tested now automatically. What’s most important, being automatically generated from the OpenAPI description of REST APIs, the test scripts themselves can now always be kept up-to-date with the latest version of your REST APIs.
Comments Sign in to post comments
Example project
Submitted by Michael Siemaszko on Sun, 2021-10-24 18:48
https://gitlab.com/oss-contrib/EclipseCon2021/example-project
K6 OpenAPI Generator code
Submitted by Michael Siemaszko on Mon, 2021-11-15 14:58
Until merge and release are ready, you can access the K6 OpenAPI Generator code utilized during the presentation at:
GitHub: https://github.com/DataInMotion/openapi-generator/ (branch:
k6-openapi-extract-examples-enhancements
)GitLab (mirror): https://gitlab.com/oss-contrib/EclipseCon2021/openapi-generator/ (branch:
k6-openapi-extract-examples-enhancements
)