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

Is your API misbehaving?(Keith-Casey)

Embed Size (px)

Citation preview

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

The API for Audio & Video Data

http://TheAPIDesignBook.com

!THE PROBLEM BDD IN CONCEPT BDD IN PRACTICE

ASSUMPTIONS

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

Assumption:

Nothing is perfect

I make mistakes

You make mistakes

Your providers make mistakes

Those other teams are knuckleheads

THE PROBLEM

API “testing” is Deceptive

Click tests - someone

Unit Tests - xUnit suite

Integration Tests - still probably xUnit

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

… no, seriously.

API Testing Sucks.

Two Goals

Prove* that it works (now)

Give you confidence (later)

Back to the Drawing Board

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

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

ENTER BDD

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.

Get your head out of the system!

What it really means..

What it looks like

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

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]

BDD IN PRACTICE

In Many LanguagesJava - JBehave

Ruby - RBehave -> RSpec -> Cucumber

PHP - Behat

Python - Behave

C# - NSpec

Javascript - Cucumber-js & Jasmine

So let’s do this

Start small.

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)

So let’s start writing!

Starting from scratch

Step 1

Write a feature!

Step 2

Refactor and reorganize things for reuse

Step 3

Implement our first step!

Step 4

Include a configuration

Step 5

Our first hard step: POST

Step 6

Look at the result

BDD IN PRACTICE (PART 2)

Step 7

Let’s add a simple read only test

Step 8

Refactor and reorganize things for reuse

Step N

Etc

BDD AT SCALE

And then…?

Write the feature

Refactor to reuse when possible

Add the left over bits

GOAL: You should be writing less and less code!

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 )

!THE PROBLEM BDD IN CONCEPT BDD IN PRACTICE

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

http://TheAPIDesignBook.com