Better Practices

For individual engineers to the largest teams, Better Practices is intended to distill knowledge from the Postman community. This is a place to learn about modern software practices together! Read more: https://medium.com/better-practices/introducing-better-practices-e9cf14cf0c88

Acing your API tests — what you need to know for test automation

Joyce Lin
8 min readNov 26, 2018

--

As Quality Engineers, we set the quality standard on our products and hold our development teams accountable.

Writing tests for our microservices keeps our products running smoothly. We would not be able to release with the high level of confidence we currently have without these tests in place to ensure that our services are running and integrated as expected.

Trent McCann, Lead Quality Engineer at Cvent

Part 1: API tests

API test for a single API request

Testing a publicly facing API through your UI is not enough!

Amber Race, Senior SDET at Big Fish Games

Examples of API tests

Tests are the documentation for your code. They should document the desired functionality of the software, and also address edge cases and error scenarios.

Valentin Despa, Software Developer at AOE

Part 2: Integration tests

We write tests because we want them to fail someday, to warn us that something is our application has changed or behaves differently. While this seems rather obvious, tests that never fail are quite common.

It can be that the test run report is not properly understood by the CI/CD tool and marked as passed, or that assertions themselves are not executed, are faulty, or too permissive. So when you write a test, make sure it can fail.

Valentin Despa, Software Developer at AOE

Setup and teardown

Automate the setup and teardown of your test conditions

Scenario tests

Generally, I take a black box approach — follow the happy-path to ensure it meets the defined functional specs and start going off that path. Try negative and edge case scenarios to see how the application will respond.

A good rule of thumb to keep in mind is: if a user can do it, they will at some point actually do it, no matter how obscure it may seem.

Trent McCann, Lead Quality Engineer at Cvent

Part 3: Other stuff that people talk about when writing tests

Performance tests

Exploratory load testing to gain a deeper understanding of your systems

Mocking dependencies

Contract testing

Consumer-Driven Contract Testing ensures that your service doesn’t break when a service that you rely on is updated

We take an API-First Design approach to ensure that our API specifications are defined and approved before cutting any code. This provides us with a unified design to build upon, and allows our developers and QE to simultaneously develop our application and tests, thereby avoiding the waiting period before the handoff from dev to QE.

We leverage the Postman mock service to ensure that our tests are developed and ready for use when handoff takes place. Then it is simply a matter of swapping variables and our QEs are off to the races.

Trent McCann, Lead Quality Engineer at Cvent

Regression testing

Tests give you confidence when adding new features and changing your code. They should not be a burden to write and maintain but a tool that can empower you as a development team to build better software.

Valentin Despa, Software Developer at AOE

Part 4: a recipe for writing Postman tests

Import this collection and follow along with these examples
Examples of writing tests in Postman

A final thought about writing tests

--

--

Better Practices
Better Practices

For individual engineers to the largest teams, Better Practices is intended to distill knowledge from the Postman community. This is a place to learn about modern software practices together! Read more: https://medium.com/better-practices/introducing-better-practices-e9cf14cf0c88

Joyce Lin
Joyce Lin

coding and cats in San Francisco

No responses yet