BDD for APIs

35
BDD for APIs Jason Harmon

description

How BDD with tools like Cucumber can create a stronger team, a better quality product, and ultimately a more useable API. Given at the #apistrat SF conference 10/24/2013

Transcript of BDD for APIs

Page 1: BDD for APIs

BDD for APIsJason Harmon

Page 2: BDD for APIs

Jason HarmonBlogger @apiuxAPI Architect @uShip

Likes PythonWorks in everything else~20 years of tech experienceBackground in many integrations

Page 3: BDD for APIs

What is BDD?“Behavior Driven Development”English readable description of how the product

behavesDefined by team up-front: not Dev, QA or product

ownedUsed to verify the acceptance criteria for features

in a productConceptually like TDD (test-first), but for

functional testing (not code architecture)

Page 4: BDD for APIs

What BDD is NOTA testing framework

Really just an English-readable UI for your own testing implementation

A drop-in solutionYou have to write the code

A UI-testing solution, like SeleniumYou can actually use Selenium as a driver for Uis,

but we’re talking APIs!

Page 5: BDD for APIs

* Agile Testing: A Practical Guide for Testers and Agile Teams (Addison-Wesley, 2009)http://lisacrispin.com/2011/11/08/using-the-agile-testing-

quadrants/

Page 6: BDD for APIs

Q2 Automated & Manual Tests

Functional TestsExamplesStory TestsPrototypesSimulations

Supp

ortin

g th

e Te

am Business Facing

BDD

Page 7: BDD for APIs

Polyglot friendlyCucumber

Ruby-based, the granddaddy of BDDhttp://cukes.info

Page 8: BDD for APIs

Polyglot friendlyCucumber-JVM

Java implementation, plays nice with Junit and all JVM languages

Groovy is quite nice herehttps://github.com/cucumber/cucumber-jvm

Page 9: BDD for APIs

Polyglot friendlySpecflow

.NET, Visual Studio integratedhttp://specflow.org

Page 10: BDD for APIs

Polyglot friendlyLettuce

Python-based, very similar to Cucumber

http://lettuce.it

Page 11: BDD for APIs

Polyglot friendlyBehat

http://behat.org

Page 12: BDD for APIs

GherkinOne Description to Rule Them All

Business ReadableDSL

Not codehttps://github.com/cucumber/gherkin

Page 13: BDD for APIs
Page 14: BDD for APIs

Gherkin ExampleImperative Style

Page 15: BDD for APIs

Gherkin ExampleDeclarative Style

Page 16: BDD for APIs

Behavior DrivenUser experience trumps all; APIs are no

exceptionTreat API consumers like first class citizensDescribe how your API behaves from a

consumer perspective

Page 17: BDD for APIs
Page 18: BDD for APIs

Step Definitions

Page 19: BDD for APIs

Scenarios“…until it’s green like a cuke”

Page 20: BDD for APIs

Scenario outlines

Page 21: BDD for APIs

ErrorsRed means stop

Page 22: BDD for APIs

Tags

Very useful for grouping features/scenariosAlso useful for ignoring

Page 23: BDD for APIs
Page 24: BDD for APIs

Prod

uct

Dev

elop

ers

Test

ers

Stak

ehol

ders

The way things used to be

Page 25: BDD for APIs

AgreementDecide during planning how you will test for

Acceptance Criteria…AS A TEAM…

Page 26: BDD for APIs

PushbackQA might be uncomfortable with code

Have dev help with a framework, QA can stick to feature files and simple step definition code

Dev might not be happy writing testsOnce they realize QA+PO signs off easy and fast,

they’ll be convincedProduct might just be afraid they have to code

or learn something “Techy”Once they realize it’s all about business lingo, i.e.

‘Domain Language’, they’re fine

Page 27: BDD for APIs

ProductivityStakeholders know what they’re gettingDevs know how to build it, less reworkTesters know how to test it, more time to

exploreProduct knows how to sign off, and quicklyDocumentation has a head start

Page 28: BDD for APIs

Domain LanguageFocus on how you describe everything

Find agreement on how to describe behavior

Recognize when behavior is different than before“Wait, we’ve never deleted before!”

Homework: Domain Driven Design

Page 29: BDD for APIs
Page 30: BDD for APIs

Share!

Page 31: BDD for APIs

Share!All BDD tests can be committed to SCM,

including branchesProvides process which allows collaborative

coding on building test frameworkCode reviews on changes to test framework

are able to be automated

Page 32: BDD for APIs

Continuous IntegrationRegression is running all the time

Use tags to select the right depth of regression

Very fast identification of what’s broken, in business language

Page 35: BDD for APIs

ThanksJason Harmon

@jasonh_n_austinhttp://jhr.mn