05/23/2017 Featured Christopher Reichert

In this post I'll describe how to automate API tests defined in a Postman Collection from a continuous integration or delivery pipeline using Assertible. Postman is fantastic tool used for exploring, testing, and defining APIs. Using Assertible in conjunction with Postman Collections gives you access to powerful automation tools like the Assertible Deployments API and scheduled monitoring, all available for free. Using Assertible also allows you to use the same tests for monitoring and continuous delivery.

There are only 3 required steps:

  1. Import a Postman Collection into Assertible
  2. Configure auth and undefined variables
  3. Invoke API tests using the Deployments API

1. Import Postman Collection into Assertible

The first step is to create a web service and tests in Assertible from your Collection. When you import a Postman Collection, Assertible will create a new web service from your primary collection URL and a test for each request item.

Steps

  • Navigate to the import form. If you don't have an account, create one here.

  • Click the Import a Postman Collection button.

  • Enter the URL your Postman Collection is hosted on (or upload a file).

  • Click Import spec to see a preview of the import.

  • Click Create service and tests.


Assertible import from Twitter API Postman Collection dry run


Get started testing your Postman Collection now!
Assertible is free to use. Contact us if you have any questions or feedback!


2. Configure auth and other variables

Many Postman Collections use variables to parameterize data in HTTP requests. For example, auth tokens, header values, query parameters, and even the host URL or port may use variables to dynamically set variables across different environments.

When you import a Postman Collection, it's possible that some values may not be completely filled out. The most important value to check for is authentication.

If your collection defines auth at the collection level, navigate to your web service's Settings view and check for the Authentication section and click Edit default auth.


Web service settings with undefined auth

If your collection defines auth or variables at the test level, navigate to the test's Configure view and you will see the Request tab. Variables with a value of undefined are marked as a TODO, as seen in the image below.


Test settings with undefined auth and variables

Simply edit these HTTP request fields to the correct values and your service will be good to go. If you need dynamic HTTP request data, based on another HTTP request or random data, use setup steps.

NOTE

  • you can avoid being forced to fill these variables out by adding parameters as Global variables in your collection.

  • If the hostname or port number for your API uses variables, for example {{URL}}, {{host}}, or https://{{hostname}}:{{port}}/api), Assertible will not be able to properly import the web service

    This can be fixed by creating a global variable defining these fields.

3. Create new deployments from continuous integration/delivery pipeline

The final step is to invoke API tests from your CI pipeline. Preferrably, API tests are executed immediately after your web service is deployed. Assertible's Deployments API is designed specifically for this use-case and is extremely easy to use.

The script below creates a new deployment in Assertible. When Assertible recieves a new deployment, it will execute the tests for your web service and register the deployment information for the web-service which can be viewed later in the dashboard.

VERSION=`git log -n 1 --pretty=format:"%H"`
SERVICE=ASSERTIBLE_SERVICE_ID

curl -u $ASSERTIBLE_API_TOKEN: -XPOST 'https://assertible.com/deployments -d'{
    "service" : "'"${SERVICE}"'",
    "environmentName" : "production",
    "version" : "'"${VERSION}"'"
}'

Bonus: GitHub status checks

If the code for your web service is hosted on GitHub, it's trivial propagate API test results to commit statuses so you can see the results of your API tests from pull requests. Check out the GitHub deployments integration for more details.

Assertible status check on GitHub pull request

Wrapping up

Using Postman Collections with Assertible, it's easy to reuse your existing work to continuously test your web services from a continuous integration or delivery pipeline.

Assertible works best with Postman Collections used to define an API with corresponding documentation rather than a Collection that defines complicated workflows using advanced Postman features. See our documentation on importing a Postman Collection for more details about the limitations and caveats.

More resources and tutorials

Have any questions or comments? I'd love to hear it! Hit me up on Twitter or reach out directly.

:: Christopher Reichert

Categories

The easiest way to test and
monitor your web services

Define and test your web service with Assertible Track and test API deployments across environments Schedule API monitoring and failure alerts

Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.

Sign up for free