06/26/2017 Changelog Cody Reichert

Introducing teardown steps: Model your API tests around real world use-cases, isolate test dependencies, and test more complex workflows using setup and teardown steps.

At Assertible, we want to promote best practices, reliability, and simplicity in our API testing platform. It's important that tests are reproducible while being flexibile enough to model real-world use cases and validate a series of HTTP requests.

This is why we're exicted to release teardown steps, the counterpart of setup steps. A teardown step is an HTTP request that runs after the test, and can be for things like testing logging out of a web app or removing test data left over from the test.

Post request teardown step in Assertible API test

Using teardown steps to clean up data from the test

Teardown step example

Signup for a free account to start testing your API

For a basic example, let's demonstrate testing a CRUD operation for a REST API. Pretend you have an API with a /users endpoint, and you want to create a test to validate POSTing a new user, ensure it was saved correctly, and delete the user after the test.

In Assertible, this would be a 3 part test:

  1. Setup step

    Create a setup step that POSTs a new user. In the setup step, you can save the id returned from the API after posting a new user in a {{userId}} test variable.

  2. Test

    The test itself will make a GET request to /users/{{userId}} using the {{userId}} variable saved in the setup step. If the setup step failed to save the variable, or it's not available, the test will fail.

  3. Teardown step

    Set up teardown step that makes a DELETE request to /users/{{userId}} using the same {{userId}} variable saved in the setup step.

This structure allows you to have a fully encapsulated, reproducible, and side-effect free API test. This test doesn't rely on previous tests setting variables correctly, and it doesn't rely on a complex series of requests as a pre-requisite.

When it comes to automating API tests, this structure is ideal becauase it lowers the probability of a flaky test, isolates test dependencies, and can easily be automated. This is a simple example, but displays the power of a structured API test framework and provides a good starting point to test more complex API workflows.

Continuing development

We have big plans for improving and extending setup and teardown steps as we continue to build and develop new tools for web service testing. Supporting capturing variables in teardown steps, and having multiple setup steps are on the roadmap, so stay tuned.

Further resources

Have a good idea, question, or want to chat about Assertible? Find me on Twitter or reach out directly - I'd love to hear what you think!

:: Cody 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