How to Automate API Testing

Preview:

Citation preview

Bruno PedroJanuary 2016

How to Automate API Testing

Summary• types of API testing

• functional testing

• API exploration

• writing and running tests locally

• automating test execution

3 types of API Testing

• unit testing

• functional testing

• load testing

increased complexity

Unit Testing• part of the development process

• usually written by developers

• tests how local code integrates with the API

• focused on request and response handling

• automated by a CI process

Unit Testing: mocking• actual API response is saved locally

• test uses local copy of API response

• several tools for different programming languages

• VCR (Ruby)

• nock (Node.js)

Functional Testing• part of the QA process

• a kind of black-box testing

• focused on response generation

• often executed periodically

• tests how the API behaves under a controlled input

Functional Testing: identification

• which API calls should be tested

• how are those calls used by the application

• what should be tested

• who should be notified if tests fail

Functional Testing: input

• usually fake data

• information that resembles real usage

• often obtained by studying user input

• updated often

Functional Testing: output• tests should be similar to unit tests

• but performed on real API calls

• additional output

• response time

• specific API responses during testing

Functional Testing: execution

• manual crafting

• manually triggered

• potentially executed periodically

• result flags CI process

API Exploration

• starts in the product development phase

• part of the product definition

• confirmed in the development process

• validated by QA

API Exploration: questions

• why are you using the API

• what API calls are used

• how does the product integrate with the API

• what happens if the API fails or is unresponsive

API Exploration: hands-on

• getting a list of all the relevant API calls

• obtaining authorization credentials if needed

• preparing fake input data

• exploring the API calls manually

API Exploration: hands-on

swagger.io getpostman.com

API Exploration: hands-on

API Exploration: hands-on

collections are a way to group API calls

Local Tests

• one-off testing

• batch testing

• easy to validate

• a way to discover unanticipated API responses

Local Tests: hands-on

written in javascript and executed locally

Local Tests: hands-on

Local Tests: hands-on

Automated Tests

• repeatable process

• periodic execution

• possibly flagging CI

• dedicated or SaaS solutions

Automated Tests: hands-on

newman

runscope.com

Automated Tests: hands-on

test scheduling using Runscope

Automated Tests: hands-on

test metrics provided by Runscope

Wrap up• unit and functional API testing

• identification, input, output and execution

• API exploration and introduction to Postman

• local testing with Postman

• automating tests with runscope

API Testing Workflow

newman

runscope.comswagger.io postman

+

Sean O’ConnorLead Engineer

It's great to see a tool like API Changelog come along. (…) as an API provider, it's always

a challenge to communicate to users when changes happen.

bpedro@apichangelog.com

Get in touch!

Bruno Pedro

Thank you

Recommended