Creating API Tests

Overview

In this article, let's look at the different ways you can test API (application programming interface) module configurations at Unqork. You can run a test to:

  • Confirm the execution sequence of your API call is correct.
  • Check that the expected API response is correct.
  • Check that specific data field responses match a specific criteria.

To set up these tests, you'll use Unqork's Testing tool. Once set up, tests execute on module save. Or, you can use the tool to manually execute them. The tool also lets you edit, delete, and monitor all your API module tests.

To learn more about the Testing tool, search Testing Tool in our In-Product help.

What You'll learn

In this article, you'll learn:

What Is an API Test?

API tests are tests you specifically use for your API modules. The following table describes the different types of tests you might see here:

API Test Description

Execution Sequence

This test monitors the execution sequence of your module. A successful test proves that all your components trigger in the correct order.

After executing the test, an Event Log displays. This shows the components and their events at each step of the execution sequence. This is very similar to what you see from the Server Side Execution Testing page.

To learn more about the Server Side Execution Testing page, search Server Side Execution Testing in our In-Product Help.

Match Response

This test compares the JSON of the expected API response against the actual API response. Both match if the test is successful.

Validate Fields

This test lets you enter a specific data field to test. You can set up criteria for that data field and check that its response meets these criteria. Validation types include:

  • Exists: Confirms the data field you entered exists somewhere in your API response.

  • Size: Confirms the size of the data field you entered. For example, let's say you expect your data field to be an array of 100 rows. To confirm the array size, you'll enter 100 in the Size field.

  • Value: Confirms the expected value for your data field is correct.

It's important to note that you can only select modules that follow Unqork's API specifications. Once you find an API module, you can set up an API test.

To learn more about API specification, search API Specification Snippet in our In-Product Help.

Create API Tests for Multiple Modules

Let's say you created a complex application involving various API modules. The best thing to do is set up API tests to ensure all those API calls work correctly. With the Testing tool, you can set up bulk Execution Sequence and Match Response API tests on all your API modules. These tests ensure the responses are accurate and the firing sequences are correct.

To create API tests for multiple modules:

1. Open the Testing tool.
2. Click Create Bulk API Tests.

When you arrive on the Bulk API Test Creator dashboard, you'll see various test options, filters, and a table of all your environment's API modules. By default, the table only shows API modules that don't have tests. This makes it easier to find API modules that need tests. Let's look at the dashboard in more detail.

Navigating the Bulk API Test Creator Dashboard

By default, the test name is Created by Bulk Test Creator. If you want a different name, click the Test Name field and rename the test. The Execution Sequence test is also the default API Test Types to Create selection. This is a recommended test for all your API modules. That said, you can deselect the test and select the Match Response test instead. Or, you can select both.

By default, every API module you see in the Selected Modules for Test Creation table is set up with your selected test(s). To run tests on specific modules, use the dashboard's filters to find them.

Here are the different filter options you can use:

Filter Description

Workspaces

Use this drop-down to filter API modules from one or more workspaces.

If you clicked the Create Bulk API Tests button from the Testing Workspace Dashboard, this drop-down automatically populates with your workspace.

Apps

Use this drop-down to filter API modules from one or more applications.

If you clicked the Create Bulk API Tests button from the Testing App Dashboard, this drop-down automatically populates with your application.

Modules

Use this drop-down to filter for specific modules.

Reset Filters

Click to reset the filters.

Include Modules with Tests

Select this checkbox to see all environment API modules with tests. You'll also still see the modules that don't have tests.

By default, this checkbox is clear. This means you'll only see environment API modules that don't have tests.

Whatever API modules you filter for displays automatically in the Selected Modules for Test Creation table. You can only run tests on modules displayed in the table. By default, the table displays 10 modules. Click the pagination at the bottom of the table to see more modules.

Let's take a look at the information you'll find in the table:

Attribute Description

Workspace

The workspace where your selected module exists.

App

The application where your selected module exists.

Module Name

The selected module's name.

Module ID

The selected module's unique identifier.

Test Status

Shows if the selected module has a test or not. Tested modules have a checkmark in this column.

Module Dashboard Button

Click this button to view the selected module in the Testing Module Dashboard.

Creating an API Test

If your API modules have service logs, the test(s) runs on the most recent one. Now, let's create a test.

To create a test:

1. Enter a test name in the Test Name field. Or, leave it to the default.
2. Select one or both of the tests from the API Test Types to Create checkboxes.
3. Use the dashboard's filters to find and display only the API modules you want to test.
4. Click Create Tests at the top of the page.

5. Click OK to confirm you want to run your test(s) on those selected modules.
6. Click OK on the modal to return to the Bulk API Test Creator.

If those modules have service logs, a Test Status checkmark displays. If they don't have service logs, No Log Found displays as the Test Status. Return to that module and execute it. Then you can set up a test for it.

Create API Tests for a Single Module

Now, let's say you only need to create API tests for a single module. You can also do this using Unqork's Testing tool.

To create one or more API tests for a single module:

1. Open the Testing tool.
2. Click Create Single API Test.
3. Select an API module from the Module drop-down.

To view the module in the Module Builder, click the View Module in Designer link.

Selecting Recent Service Log API Request Data

If your module has recent service logs, you'll see these details populate automatically:

  • The most recent service log timestamp (Recent Service Logs).

  • The service log ID (Service Log ID).

  • The log's API request (Request).

  • The log's API response (Response).

To look at a different service log, select it from the Recent Service Logs drop-down. Then, click the View Service Logs Dashboard link for more details about your chosen service log.

Manually Entering API Request Data

If no service logs exist, you must enter your API request manually.

After selecting a module to test:

1. Select Enter JSON Manually as your Request / Response Data.

This is the default setting if no service logs exist for this module.

2. Enter your API request JSON in the Request field.
3. Below the Request field, click Get Response. API response data displays in the Response field.

Creating an API Test

Now that you have an API module selected, let's create an API test.

To create a new  test:

1. Click Add Test at the bottom of the page.
2. Enter a unique test name in the Test Name field.
3. Select a Test Type.

Depending on the Test Type, different information displays on the page. Here are the fields you see for each test.

Test Test Details

Execution Sequence

Request field: The tested API request displays in the Request field.

Event Log: This log shows you the full sequence of your API call. This includes the components, events, and the steps the events occur in.

Match Response

Request field: You'll see the tested API request in the Request field.

Expected Response field: This field shows you the expected API response for your API module.

Validate Fields

Request field: You'll see the tested API request in the Request field.

Test Details: This is where you enter a data field and criteria to test.

Below is an example of what you would see if you selected the Execution Sequence Test Type.

Using the Validate Fields Test Type

Of the Test Types, Validate Fields is the only one that asks you for extra information. After selecting Validate Fields, you'll see the following options display:

Attribute Description

Data Field

The data field you want to test.

Validation Type

The type of validation you want to test. The options include Exists, Size, and Value.

Exists

Confirms the data field you entered exists somewhere in your API response.

Size

Confirms the size of the data field you entered. For example, let's say you expect your data field to be an array of 100 rows. To confirm the array size, you'll enter 100 in the Size field.

Value

Confirms the expected value for your data field is correct.

Condition

This drop-down only displays if you select the Size or Value Validation Types.

Equals

Checks the Size or Value you entered equals the Data Field.

Contains

Checks the Size or Value you entered is part of the Data Field.

Is Greater Than

Checks to see if the Data Field is greater than the Size or Value entered.

Is Less Than

Checks to see if the Data Field is less than the Size or Value entered.

Not Equal To

Checks the Size or Value you entered doesn't equal the Data Field.

Value

The size or value you want to test when you select the Size or Value Validation Type.

+ Add Button

Click this button to set up the API test.

To help you understand the Validate Fields Test Type, let's look at how to use it:

1. Enter a unique test name in the Test Name field.
2. Select a Test Type.
3. Enter a specific data field in the Data Field field.

Examples of data fields could be key or array.0.key.

4. Select a Validation Type.

If you select Size:

a. Select a condition from the Condition drop-down.
b. Enter the size of the array in the Size field.

If you select Value:

a. Select a condition from the Condition drop-down.
b. Enter the response value for your data field in the Value field.

5. Click + Add.

Repeat these steps to add more validations. You can add as many validations as you want.

6. Click Save.

Your focus returns to the previous test page. You now see your new tests added to the bottom of the page. Click Create Test and your tests will execute.

Below is an example of what you might see:

Now, every time you save your module, these tests run.