apic docs
  • About APIC
  • Installing APIC
  • Getting started with APIC
  • Designer
    • Getting Started With APIC designer
    • Working with API project
    • Creating a Folder
    • Creating a Model or Definitions
    • Creating a Trait
    • Creating an Endpoint
    • Write API Tests starting from Design Phase
    • API Security Definitions
    • Export and view Docs
  • Tester
    • Make an API call
    • Sending Forbidden request headers with APIC
    • Viewing API Response
    • Managing Environments
    • Using Environments
    • Using the Test Builder
    • Writing Test Cases
    • Response Schema validation
    • Creating Test Suites
    • Test Websocket
  • Test Real User Sessions
  • APIC Command line interface (apic-cli)
  • APIC Web Agent (apic-cli)
  • APIC CI/CD Integration (with Jenkins)
  • API Documentation
  • Simulator
  • Dashboard
    • Team Management
    • Published Docs
  • Sharing
Powered by GitBook
On this page
  • Writing tests during design
  • Defining tests based on API response
  • Adding more tests

Was this helpful?

  1. Designer

Write API Tests starting from Design Phase

PreviousCreating an EndpointNextAPI Security Definitions

Last updated 5 years ago

Was this helpful?

Writing tests during design

As a typical practice for writes test for your APIs only starts after the design/spec for the API are complete. Then the testes are explained the use of that API to start writing tests. But the ideal thing to do is to start writing some initial tests for the APIs during the design phase. And this should be done by person designing the API spec as he/she will have better understanding of the API while its being designed and as to what scenarios to test for the APIs.

Well what if there was a way to do all this? That's what API is for.

Defining tests based on API response

APIC has a very simple tool to define response schema for your API during design. We call it The Schema designer. With this you can define response schema against different status codes. Just add a new status code from the left panel and start defining your schema.

Having done that now you can add tests based on your response. To do that click on the Test Builder icon beside each property (as shown below) which will open up the tool to write tests against your response schema as shown below.

The above screen grab shows an example where you are defining the spec for a [POST] Create ToDo API which accepts the name of the ToDo and returns the newly created ToDo along with its id, name, completed and created fields. A simple test would be to check the value of the name field in response should be the same as the value specified in the POST request payload.

Adding more tests

Using the above Test Builder you can write tests based on your API response schema. But writing tests isn't just limited to response schema. You can write a whole lot of other tests while defining your endpoint.

  • Pre Run Scripts - These scripts run before your API request is made. An ideal place to generate random data, storing values in environment variables etc.

  • Post Tun Scripts - These scripts run once the response is received. An ideal place to write your tests/assertions(ex: Making sure that the status code for Create ToDo is 201, or the response time is less than 2 sec) or to store and fields from the response as an environment variable (ex: Storing the id of the newly created ToDo from the response as an environment variable to be used in the Get ToDo by ID API call).

There are some predefined snippets to help you add more tests.

If you want to reuse a schema you can define it as a or and add reference it here with $ref. You can even expand it inline to view its properties.

To add more tests scroll down to the Test Scripts section in the . Here you have to option of defining 2 types of scripts

Model
Trait
Learn more about the Test Builder here.
Endpoints panel
Response Test builder