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.
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 POST
ing a new user, ensure it
was saved correctly, and delete the user after the test.
In Assertible, this would be a 3 part test:
Setup step
Create a setup step that
POST
s a new user. In the setup step, you can save theid
returned from the API after posting a new user in a{{userId}}
test variable.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.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
- Creating setup steps: using variables in your test
- Configuring a test in Assertible
- Teardown step documentation
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
Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.
Get started with GitHubSign up for freeRecent posts
Tips for importing and testing your API spec with Assertible 05/26/2020
New feature: Encrypted variables 10/30/2019
New feature: Smarter notifications 5/17/2019