Awesome
API testing example
The purpose of this document is to be an easy guide for devs and testers to start testing REST APIs just in minutes.
For the examples we will be testing the Uber API using a YAML Swagger / Open API file and Reqres API using a normal Request Hash file.
To generate the Request Hashes from a Swagger / Open API file, run the file ./utils/import_swagger.rb or use the open_api_import command line executable.
If you want to automatically generate RSpec tests for every end point of your Swagger file, use the create_tests gem: https://github.com/MarioRuiz/create_tests
Installation
-
Install Ruby >=2.4. Recommended last 2.5 stable release. To see which version you already have installed:
ruby -v
-
Install the libraries we use by running from root folder:
bundle install
Documentation
General
Libraries
Running tests
To run all the tests:
rspec
To run a particular test file:
rspec ./spec/my_test_spec.rb
To run a particular test (example) inside a test file, add the line number where the test is:
rspec ./spec/my_test_spec.rb:42
The default values to set all tests are on settings
folder. You can pass parameters to overwrite the settings in command line or ENV variables.
HOST=10.20.30.50 rspec ./spec/my_test_spec.rb