Introduction
The process of testing software during development helps find problems early. But running the tests manually can easily become tedious as a project grows in size. Testing automation makes development more enjoyable for developers. We can forget about running tests and focus on development.
This is Part 2 of a series about API Testing. In Part 1 we learned how to create and run tests for an API. This tutorial will introduce you to API testing automation.
You will learn to:
- setup testing schedules,
- run the tests automatically, and
- enable continuous integration testing.
API Testing
What is an API? APIs are usually URLs that we can request to get what we want. See the previous post in this series to get the basics.
Comparing GUI Testing
Compared to the difficulty and fragility of testing the graphical components of an application, testing its API is simple and easy to code. The business logic of an application includes important things like product pricing and quantity discounts, for example. If we code the business logic into the presentation layer then testing it involves a whole slew of very complex graphical control equipment unrelated to pricing. So, this makes testing unnecessarily complicated increasing setup time and run time.
Therefore, it is smart to move the business logic out of the presentation layer. A better place for business logic is in a separate services layer. We then make our pricing information available to the GUI via an API call. In the end, our API tests run much faster and point more closely to the issues.
Comparing Unit Testing
API testing differs from unit testing in multiple ways. Here are a few of them.
Unit Testing | API Testing | |
Conductor | Development team | QA team |
Build chronology | Before the build | After the build |
Box type | White box | Black box |
Source code | Analyzed | Not analyzed |
Scope | Limited | Wide |
API Testing Automation
Testing automation is the process of setting up and executing reusable groups of tests hooked to certain events. For example whenever we push code to the repository then the tests hooked to the push event run.
Related: Best Automated Testing Tools
Testing Automation: The Cons
What are some of the contrary reasons (excuses?) to NOT automate your API tests?
- The production environment is not mission-critical
- The code-base is small and uses a single language
- The development team is small, maybe a one-man shop
- Automation takes time to research, setup and configure
- We love cascading bugs
Testing Automation: The Pros
Here are some good reasons to automate your API tests.
- The production environment is mission-critical, down-time means lost money
- The code-base is large and includes multilingual sites
- The development team is large, maybe includes a few lazy programmers
- Manual testing is time-consuming
- When manual testing becomes boring it becomes error-prone
Reviewing Our Tests
If you remember from the previous post in this series We created an API and a test for it on RapidAPI. Now we’re going to automate that test.
Step 1. Login to RapidAPI
Direct your browser to the RapidAPI Testing Dashboard:
Note: You may have to login if you’re not already.

Click on the Petstore API box to configure the Petstore test:

You should now be looking at the Petstore dashboard.
Step 2. Run the Test in UI
Let’s run the test manually to make sure it’s still working. If you are having any problems refer to the previous post and retrace your steps.
Click on the Actions menu button for My First Test
to open the actions menu:

Click Run
:

The test will run on RapidAPI’s servers and the status box will appear in the Recent Results list. When you click on the results then the Execution Report will pop up:

Automating Our Tests
Step 3. via CI Trigger URL
If we want to include the test in our continuous integration (CI) pipeline there are a couple ways to do it. The first way to do it is to call a RapidAPI Trigger endpoint. Let’s check our test settings to do just that.
Click on the Actions menu button for My First Test
to open the actions menu and then click on Edit
.
On the edit page, click on the Settings
tab and look for the API Endpoint URL under the CI/CD INTEGRATION section:

Let’s visit this API Endpoint URL in a web browser. You could type it in manually but it’s probably way easier to copy/paste.
When you press enter to make the API call RapidAPI will queue your request and return the JSON response which will look something like:
{"success":true,"message":"Test My First test has been queued for execution. Once done, you can see the test execution report here: https://rapidapi.com/testing/dashboard/api/test/results/report?api=api_7872458e-9e30-4881-8fc9-4113019366b0&test=test_9a0adb24-59c5-4d08-b783-74c8e0d34a16&testExecution=testexecution_845129b5-74aa-4dcb-9c6f-6f8189afd766","reportUrl":"https://rapidapi.com/testing/dashboard/api/test/results/report?api=api_7872458e-9e30-4881-8fc9-4113019366b0&test=test_9a0adb24-59c5-4d08-b783-74c8e0d34a16&testExecution=testexecution_845129b5-74aa-4dcb-9c6f-6f8189afd766","executionId":"testexecution_845129b5-74aa-4dcb-9c6f-6f8189afd766","location":"local","queued":"2020-11-29T01:36:19.000Z","statusUrl":"https://rapidapi.com/testing/api/trigger/execution/testexecution_845129b5-74aa-4dcb-9c6f-6f8189afd766/status"}
The formatted output looks like:

Looking at the formatted output we can see the message
:
“Test My First test has been queued for execution. Once done, you can see the test execution report here: https://rapidapi.com/testing/dashboard/api/test/results/report…”
If you paste that Report URL into your browser you will see the Execution Detail Report:

Step 4. via CI GitHub Action
As I mentioned in the previous section, there are a couple ways to include tests in our continuous integration pipeline. We just covered the first way, calling an API Trigger Endpoint. The second way is to use the RapidAPI Testing GitHub Action.
GitHub Actions make it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want. —GitHub
Note: You will need a GitHub account for this step in the tutorial.
The only piece of information you will need from your test is the ID which can be found at the bottom of the settings page:

Create GitHub Repository
Note: You will need to be logged into GitHub at this point.
From any GitHub page click on the plus sign in the upper right and select New repository
:

On the Create a new repository page enter a Repository name
and click Create repository
:

Create New File for our Action
Once your repository has been created you will see instructions how to add content.
We are going to create a file to hold our GitHub Actions code. This action will be run automatically based on the event hook we define. In our case we will define this event as the push event. This means that anytime new commits are pushed to the repository our action will run.
Click on creating a new file
:

Our action code uses some actions from another GitHub action; namely, RapidAPI/gh-api-testing-trigger.
On the editor page enter in the following text:
on: [push] jobs: run_api_test: runs-on: ubuntu-latest name: Execute RapidAPI API Tests steps: - name: Execute Tests id: tstExec uses: RapidAPI/gh-api-testing-trigger@master with: test: 'test_9a0adb24-59c5-4d08-b783-74c8e0d34a16' location: 'AWS-US-EAST-1' - name: Show Results run: echo "The test took ${{ steps.tstExec.outputs.time }}ms to run"; echo "The test result was ${{ steps.tstExec.outputs.succesful }}"; echo "View Report - {{ steps.tstExec.outputs.reportUrl }}"
The file-path should be: .github/workflows/api.yml
Note: The directory path .github/workflows/
is required (did you notice the dot in the front of .github
)? The file name api.yml
can be anything you want just as long as it ends with the extension .yml
.

Note: Be sure to enter in YOUR OWN Test ID that we saw earlier in the RapidAPI Petstore Settings.
Then scroll to the bottom and press Commit new file
:

View Results
Since we have defined our action event hook to be on: [push]
then every time we push any commits to the repository we will trigger this action to run. Let’s go to the Actions page to see if our test ran.
Click on the Actions
tab:

We can see that indeed our action did run. Now let’s go back to our RapidAPI Dashboard to see if our test got executed:

Everything looks to be in order. Our GitHub Action got fired when we pushed that first commit and if you entered the Test ID in correctly then RapidAPI will be instructed to run our test. We can see that the AWS-US-EAST-1
location ran in northern Virginia three (3) minutes ago.
Step 5. Schedule Tests
We’ve talked about running your RapidAPI tests from your CI pipeline. Did you know that it is also possible to schedule them directly on rapidapi.com? We schedule tests to run at a certain frequency like once an hour or once a day.
See also: the documentation.
Back over on our Rapid API Testing dashboard click on the Schedule
tab and then click + Add Schedule
:

In the ADD SCHEDULE form:
- Select Frequency –
Every 1 minute
, - Locations –
local
(Default), - then click
Submit
:
Note: If you want to learn how to configure multiple environments then have a look at the documentation.

The test results will show up under RECENT RESULTS in the left column:

The test will continue to run every minute until we stop it. Once we see it run a couple times we can get the idea so let’s delete the schedule now:
Click the garbage can button:

The test schedule should now be gone.
Wrapping Up
Now that all is said and done, I hope you enjoyed this tutorial. Perhaps you learned something about API testing automation. If you have any questions be sure to leave them in the comments below.
Series
This article is the second in a series about API Testing. The first part is called: Intro To API Testing With RapidAPI.
FAQ
Frequently Asked Questions
What are the benefits of API testing automation?
The main reason to automate API tests is a Faster Release Cycle. When you move your tests to continuous integration (CI) pipeline you are better equipped to deploy your code faster and get new features to your users faster. This is especially advantageous as it provides for more opportunities to be 'First To Market' in highly competitive environments. And since each release is smaller there is less risk that something will break. Costs are also reduced without the need for someone to manually provision the test environments. Overall we get higher quality software as bugs are detected earlier and not cascaded into other components.
What is RapidAPI Testing?
RapidAPI Testing is a cloud-based API testing solution that enables enterprises to create and manage comprehensive API tests from development through deployment. It supports any API type including REST, SOAP, and GraphQL, and offers an intuitive UX that simplifies testing, monitoring, management, and integration across the development lifecycle. Find out more at docs.rapidapi.com
Leave a Reply