How to Automate API Testing

27
Bruno Pedro January 2016 How to Automate API Testing

Transcript of How to Automate API Testing

Page 1: How to Automate API Testing

Bruno PedroJanuary 2016

How to Automate API Testing

Page 2: How to Automate API Testing

Summary• types of API testing

• functional testing

• API exploration

• writing and running tests locally

• automating test execution

Page 3: How to Automate API Testing

3 types of API Testing

• unit testing

• functional testing

• load testing

increased complexity

Page 4: How to Automate API Testing

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

Page 5: How to Automate API Testing

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)

Page 6: How to Automate API Testing

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

Page 7: How to Automate API Testing

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

Page 8: How to Automate API Testing

Functional Testing: input

• usually fake data

• information that resembles real usage

• often obtained by studying user input

• updated often

Page 9: How to Automate API Testing

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

Page 10: How to Automate API Testing

Functional Testing: execution

• manual crafting

• manually triggered

• potentially executed periodically

• result flags CI process

Page 11: How to Automate API Testing

API Exploration

• starts in the product development phase

• part of the product definition

• confirmed in the development process

• validated by QA

Page 12: How to Automate API Testing

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

Page 13: How to Automate API Testing

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

Page 14: How to Automate API Testing

API Exploration: hands-on

swagger.io getpostman.com

Page 15: How to Automate API Testing

API Exploration: hands-on

Page 16: How to Automate API Testing

API Exploration: hands-on

collections are a way to group API calls

Page 17: How to Automate API Testing

Local Tests

• one-off testing

• batch testing

• easy to validate

• a way to discover unanticipated API responses

Page 18: How to Automate API Testing

Local Tests: hands-on

written in javascript and executed locally

Page 19: How to Automate API Testing

Local Tests: hands-on

Page 20: How to Automate API Testing

Local Tests: hands-on

Page 21: How to Automate API Testing

Automated Tests

• repeatable process

• periodic execution

• possibly flagging CI

• dedicated or SaaS solutions

Page 22: How to Automate API Testing

Automated Tests: hands-on

newman

runscope.com

Page 23: How to Automate API Testing

Automated Tests: hands-on

test scheduling using Runscope

Page 24: How to Automate API Testing

Automated Tests: hands-on

test metrics provided by Runscope

Page 25: How to Automate API Testing

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

Page 26: How to Automate API Testing

API Testing Workflow

newman

runscope.comswagger.io postman

Page 27: How to Automate API Testing

+

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.

[email protected]

Get in touch!

Bruno Pedro

Thank you