Top Banner
IS YOUR API MISBEHAVING? D. KEITH CASEY, JR AUSTIN, TX [email protected] @CASEYSOFTWARE
39

Is your API misbehaving?(Keith-Casey)

Aug 03, 2015

Download

Documents

Future Insights
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Is your API misbehaving?(Keith-Casey)

IS YOUR API MISBEHAVING? D. KEITH CASEY, JR AUSTIN, TX [email protected] @CASEYSOFTWARE

Page 2: Is your API misbehaving?(Keith-Casey)
Page 3: Is your API misbehaving?(Keith-Casey)

The API for Audio & Video Data

Page 4: Is your API misbehaving?(Keith-Casey)

http://TheAPIDesignBook.com

Page 5: Is your API misbehaving?(Keith-Casey)

!THE PROBLEM BDD IN CONCEPT BDD IN PRACTICE

Page 6: Is your API misbehaving?(Keith-Casey)

ASSUMPTIONS

Page 7: Is your API misbehaving?(Keith-Casey)

Assumption:

You have a technical background

APIs are an important part of your job

Use them on a regular basis

Potentially build them too

Sometimes public, sometimes private

Page 8: Is your API misbehaving?(Keith-Casey)

Assumption:

Nothing is perfect

I make mistakes

You make mistakes

Your providers make mistakes

Those other teams are knuckleheads

Page 9: Is your API misbehaving?(Keith-Casey)

THE PROBLEM

Page 10: Is your API misbehaving?(Keith-Casey)

API “testing” is Deceptive

Click tests - someone

Unit Tests - xUnit suite

Integration Tests - still probably xUnit

Web/UI Tests - Selenium, Watir, Testlio (mobile), etc

Page 11: Is your API misbehaving?(Keith-Casey)

… no, seriously.

API Testing Sucks.

Page 12: Is your API misbehaving?(Keith-Casey)

Two Goals

Prove* that it works (now)

Give you confidence (later)

Page 13: Is your API misbehaving?(Keith-Casey)

Back to the Drawing Board

SMART Specific, Measurable, Achievable, Relevant, Time-boxed

INVEST Independent, Negotiable, Valuable, Estimable, Small, Testable

Page 14: Is your API misbehaving?(Keith-Casey)

ENTER BDD

Page 15: Is your API misbehaving?(Keith-Casey)

Behavior Driven DevelopmentStandard Definition:

BDD is a synthesis and refinement of practices stemming from TDD and ATDD.

Dan North’s Definition (circa 2009):

BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.

Page 16: Is your API misbehaving?(Keith-Casey)

Get your head out of the system!

What it really means..

Page 17: Is your API misbehaving?(Keith-Casey)

What it looks like

As a [role] I want [feature] so that [benefit]

Page 18: Is your API misbehaving?(Keith-Casey)

Well to be more precise

It’s English, but in the Gherkin syntax so this:

As a [role] I want [feature] so that [benefit]

becomes a feature called:

Given [condition] when I [action] then [result]

Page 19: Is your API misbehaving?(Keith-Casey)

BDD IN PRACTICE

Page 20: Is your API misbehaving?(Keith-Casey)

In Many LanguagesJava - JBehave

Ruby - RBehave -> RSpec -> Cucumber

PHP - Behat

Python - Behave

C# - NSpec

Javascript - Cucumber-js & Jasmine

Page 21: Is your API misbehaving?(Keith-Casey)

So let’s do this

Start small.

Page 22: Is your API misbehaving?(Keith-Casey)

For Clarify.ioThe first thing that anyone does:

Creates a bundle (audio or video package)

We need a file (audio in this case)

We need an API key

We need to submit it (POST)

We need to check the results (201 Created)

Page 23: Is your API misbehaving?(Keith-Casey)

So let’s start writing!

Starting from scratch

Page 24: Is your API misbehaving?(Keith-Casey)

Step 1

Write a feature!

Page 25: Is your API misbehaving?(Keith-Casey)

Step 2

Refactor and reorganize things for reuse

Page 26: Is your API misbehaving?(Keith-Casey)

Step 3

Implement our first step!

Page 27: Is your API misbehaving?(Keith-Casey)

Step 4

Include a configuration

Page 28: Is your API misbehaving?(Keith-Casey)

Step 5

Our first hard step: POST

Page 29: Is your API misbehaving?(Keith-Casey)

Step 6

Look at the result

Page 30: Is your API misbehaving?(Keith-Casey)

BDD IN PRACTICE (PART 2)

Page 31: Is your API misbehaving?(Keith-Casey)

Step 7

Let’s add a simple read only test

Page 32: Is your API misbehaving?(Keith-Casey)

Step 8

Refactor and reorganize things for reuse

Page 33: Is your API misbehaving?(Keith-Casey)

Step N

Etc

Page 34: Is your API misbehaving?(Keith-Casey)

BDD AT SCALE

Page 35: Is your API misbehaving?(Keith-Casey)

And then…?

Write the feature

Refactor to reuse when possible

Add the left over bits

GOAL: You should be writing less and less code!

Page 36: Is your API misbehaving?(Keith-Casey)

Our StatusWe validate the Helper Libraries with this too

Feature tests for the API using:

Using the PHP library

Using the Python library

Using the Ruby library (newest)(publicly launching our tests this month here: https://github.com/Clarify )

Page 37: Is your API misbehaving?(Keith-Casey)

!THE PROBLEM BDD IN CONCEPT BDD IN PRACTICE

Page 38: Is your API misbehaving?(Keith-Casey)

IS YOUR API MISBEHAVING? D. KEITH CASEY, JR AUSTIN, TX [email protected] @CASEYSOFTWARE

Page 39: Is your API misbehaving?(Keith-Casey)

http://TheAPIDesignBook.com