API Testing Tutorial: API Testing with RapidAPI
Tags: api, testing, tutorial, qa
Published: 2020-10-21 19:33:44


Watch the video tutorial for a walkthrough of the RapidAPI Testing. Then follow the step-by-step tutorial below to create your own API and start testing!

<video width="500" controls><source type="video/mp4" src="https://rapidapi.com/blog/wp-content/uploads/2020/10/APIs-_-RapidAPI-Testing.mp4?_=1" /><a href="https://rapidapi.com/blog/wp-content/uploads/2020/10/APIs-_-RapidAPI-Testing.mp4">https://rapidapi.com/blog/wp-content/uploads/2020/10/APIs-_-RapidAPI-Testing.mp4</a></video>

# Start Testing with RapidAPI

In this tutorial, you'll learn how to [test an API using RapidAPI Testing](https://rapidapi.com/products/api-testing/). First, we'll create a new API from an API specification file. Then, we will walk through how to quickly generate tests using the testing dashboard. Towards the end, we'll talk about how you can set up testing environments, schedule tests, and set alerts for failed tests.

## Download API Spec

This tutorial uses a Swagger [API Specification](https://rapidapi.com/blog/how-to-document-your-api/) for an example API named Pet Store. You can click the link below to download the [JSON](https://rapidapi.com/blog/api-glossary/json/) file. [Download Pet Store Swagger API Spec](https://rapidapi.com/blog/wp-content/uploads/2020/10/swagger-pet-store.json) Now that you have the file, we are ready to create our API on the RapidAPI Testing dashboard.

## Create a New API

Navigate to the testing dashboard at [rapidapi.com/testing/dashboard](https://rapidapi.com/testing/dashboard). You may need to sign in to your RapidAPI account. After signing in, select **Create API** in the top right of the page. 

![Create new api button](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-13-at-1.55.06-PM-1024x348.png) 

In the pop-up, enter the new API's information:

*   Select the **Context**
*   Enter an appropriate API name (**Pet Store**)
*   Select the API specification file
*   Choose OpenAPI for **Definition type**

Click **OK**. 

![new API form ](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-13-at-1.57.47-PM.png) 

The new API should appear on your testing dashboard alongside any existing APIs. Also, it will appear in the account context that you chose when creating the API. Click on the new API tile to enter the Pet Store API testing dashboard.

## Build a Test

On the next page, click **Create Test.** Name the test _Add Pet_. After you name the test, you'll be taken to the user interface for building tests. You have the option to build tests manually. However, it's easier to use the **Request Generator**.

### Inspect Request Generator

At the bottom of the _Add User_ test dashboard. Click on the highlighted **Request Generator** bar. 

![request generator bar](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-13-at-2.29.09-PM-1024x365.png) 

After clicking on the Request Generator, a new pane will appear that has three sections. On the left, you'll see your endpoints. If you click on an endpoint, the middle pane will populate with the information (and sample data) for that route. 

![request generator left pane with add pet selected](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-7.41.40-AM-1024x409.png) 

Click the **Send** button in the middle section next to the route's URL. You should receive a successful response in the right section if your API has valid sample data. 

![Successful pet store response](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-7.44.31-AM-289x300.png) 

Now that you have received a response, we can add this outcome to our _Add Pet_ test. Click **Add to Test**.

### Select Assertions

A new pop-up will appear asking us what parts of the response we want to add to the test. Here, we toggle properties on-or-off. If a property is _on, _then it will be added to the test. Furthermore, we can use the dropdown on the right to modify the type of assertion. In the image below, I have selected various assertions that I feel fit the properties best. 

![test assertions popup](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-7.46.50-AM.png) 

Once we finish checking out assertions, click **OK** at the bottom of the pop-up. Close the **Request Generator** and observe all the assertions that we have now added, as individual steps, to our test. You use the drag-and-drop feature to modify the order of test steps. Additionally, you can modify the content of steps by selecting the angle icon on the right of each step. 

![angle bracket selected](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-7.55.33-AM-1024x288.png) 

Now, we are ready to run the test.

### Run Test & View Results

At the top right of the _Add Pet_ test dashboard, click **Save & Run. ** The test runs successfully, and the result should appear in the bottom left of the test dashboard. 

![](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-8.04.45-AM.png)

Click on the new result to view the **Execution Report**. The report displays the test conditions and details aspects of individual steps. For example, the `apiResponse.data.id` attribute is of type number, but the value is also displayed in the report. Furthermore, you can compare the response schema with your test schema by selecting **Show Details** for steps. 

![test details](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-12.16.03-PM-1024x367.png)

If a test fails, the value that caused the test to fail is displayed in the **Execution Report**. This makes it easier to find and fix errors.

## Chain Requests Together

Some APIs have endpoints that work together or use the same data. We can test API functionality and integrity by chaining different requests together.

### Create Pet

First, navigate back to the _Pet Store Tutorial API_ dashboard, and create a new test. Name the test _Add-Get Pet_. Then, in the **Request Generator**:

*   Select the _addPet_ endpoint
*   Click on the **Body** tab, underneath the URL, and select **json**
*   Send a request to get a response
*   Select **Add to Test**

This time, we are only going to test whether the **status** parameter returns a 200 status code. 

![assert test status code is 200](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-12.27.21-PM.png) Click **OK **to add it to our test.

### Creating Test Variables

It's advantageous to incorporate test variables into chained requests so that the value can be updated—or tested—quickly. In this example, we want to use a common ID value to create and then get a pet. There are two ways to set a test variable. One way is to select the **Settings** option in the navigation bar and add variables to test context in the **Test Variables** section. 

![test variable section in settings](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.03.51-PM-1024x349.png)

The second way is to create a step in the test where you set a variable. Back in the _Add-Get Pet_ test, click the **Add Step **area to add a new step. You will see a list of different types of steps that are available. Select the **Set Variable** option. Drag this new step to the top of our steps, and open the step editor by clicking the angle-down icon on the right side of the step. For the **Key**, enter _petId_, and for the **Value** enter _9222645476172562000_. 

![set variable](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.00.36-PM.png) 

This _petId_ test variable will now be available in later steps using the syntax `{{petId}}`.

### Using Test Variables

In the _Add Pet_ request, modify the JSON body to include the petId variable. 

![petId variable in JSON body](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.00.54-PM.png) 

Next, open up the **Request Generator** again and select the _getPetById_ endpoint. Replace the last item (`undefined`) in the URL with the value `{{petId}}`. Then, send the request. It's ok if it fails. 

![petId to URL](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.18.20-PM-1024x227.png)

Click **Add to Test**. Then, unselect all items from the pop-up so only the HTTP request is added to the test. Next, add a new step that asserts the status code for our GET request is 200. 

![add assertion](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.22.29-PM-1024x387.png) 

Finally, assert that the ID returned in the response is the same as the ID that we set at the beginning of the test. 

![set assertion for pet id at the end of the steps](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.02.37-PM.png) 

The full test should now have the following steps:

1.  Set test variable _petId_ to 9222645476172562000
2.  Send a POST request to add a pet (with _petId_ variable in JSON body)
3.  Assert that the response is equal to 200
4.  Send a GET request, using the _petId_ variable to fetch the new pet.
5.  Assert that the status is 200
6.  Assert that the returned ID for the pet is equal to the _petId_ variable.

![all the steps for this test](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.28.32-PM-1024x479.png) 

Click **Save & Run**. 

![execution report for chained test](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.29.48-PM.png)

The test should be successful. Next, let's take a look at how to create testing environments.

## Using Environments

To create environments, click on the **Settings** icon in the left navigation. 

![settings button on left navigation bar](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.31.17-PM.png) 

In the **Test Environments** section, click on the **+** icon to name your new environment. Environments show up as tabs along the top of the **Test Environments** section. You define environment variables the same way you define test variables. For this example, you can change the URL for your tests by specifying the _protocol_ and _domain_. I specified two variables for each environment. 

![production environmnet](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.36.48-PM-1024x277.png) 

![development environment](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-07-at-11.09.34-AM.png) 

Back in the individual tests, I can modify the URLs for each request and select the environment I want to use before I execute a test. 

![using environments in a test](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.39.52-PM-1024x437.png) 

With the environment variables, we can share variables across different tests. With test variables, we can scope values that are important to a specific test.

## Scheduling Tests and Setting Alerts

With RapidAPI Testing, you can schedule tests to run from different locations around the world and with different environments. To schedule a test, select the test that you want to schedule from the dashboard. Click on the **Schedule **option in the side navigation. Choose the:

*   Frequency
*   Environment
*   Locations

![scheduling tests](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.42.26-PM-1024x502.png) 

Now that your test is scheduled, go to the main API test settings. This is the same location where we defined test environments. You can select to either receive **Email** or **SMS** alerts when a test for this API fails. 

![setting alerts](https://rapidapi.com/blog/wp-content/uploads/2020/10/Screen-Shot-2020-10-14-at-1.45.16-PM-1024x313.png)

## Conclusion

In this brief tutorial, we covered how to test your API using RapidAPI Testing. Also, we looked at making basic assertions. However, there are a variety of different types of test steps that can be utilized to test more complex scenarios, including:

*   Custom code
*   Looping over responses
*   Logical assertions (If/Else checks)

Now that you understand the basics of how to test APIs, I encourage you to try it out with your own API.