Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Is Your API Misbehaving (workshop)

Keith Casey
November 05, 2015

Is Your API Misbehaving (workshop)

Most API testing is a joke. We have things that resemble Unit Tests which are really integration tests which really just wrap our personal understanding in just a bit of code. And at the end of the day, we're still not sure it works. Instead, let's flip the entire experience around and look at it from the API consumer's point of view and confirm that we're solving real problems for real users. In this talk, we'll dive into some of the benefits of Behavior Driven Development and build some examples.

Keith Casey

November 05, 2015
Tweet

More Decks by Keith Casey

Other Decks in Technology

Transcript

  1. Is Your API
    Misbehaving?
    D. Keith Casey Jr
    [email protected]
    @CaseySoftware

    View full-size slide

  2. Who am I?
    Clarify.io -
    The API for businesses
    to build apps that
    Search and Understand
    their Audio & Videos

    View full-size slide

  3. Who am I?
    http://TheAPIDesignBook.com

    View full-size slide

  4. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  5. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  6. Assumptions
    • 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
    7

    View full-size slide

  7. Assumptions
    • Nothing is perfect
    • You make mistakes
    • Your providers make mistakes
    • That other team are knuckleheads
    8

    View full-size slide

  8. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  9. • Click Tests - someone
    • Unit Tests - xUnit suite
    • Integration Tests - still probably xUnit
    • Web/UI Tests - Selenium, Watir, Testlio (mobile)
    API Testing is Deceptive
    10

    View full-size slide

  10. … no seriously.
    API Testing Sucks
    11

    View full-size slide

  11. Two Goals
    Prove* that it works (now)
    Give us confidence (later)
    12

    View full-size slide

  12. Back to the Drawing Board
    13
    • SMART
    • Specific, Measurable, Achievable,
    Relevant, and Time-boxed
    • INVEST
    • Independent, Negotiable, Valuable,
    Estimable, Small, Testable

    View full-size slide

  13. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  14. BDD - Standard Definition
    15
    BDD is a synthesis and refinement
    of practices stemming from
    TDD and ATDD

    View full-size slide

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

    View full-size slide

  16. BDD - What it really means
    17
    Get your head out of the system!

    View full-size slide

  17. BDD - What it looks like
    18
    As a [role], I want [feature]
    so that [benefit]

    View full-size slide

  18. BDD - To be more precise
    19
    It’s English but in the Gherkin syntax so this:
    • As a [role], I want [feature] so that [benefit]
    becomes a feature (or spec) structured as:
    • Given [condition], when I [action] then [result]

    View full-size slide

  19. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  20. In lots of languages
    21
    • Java - JBehave
    • Ruby - RBehave -> RSpec -> Cucumber
    • PHP - Behat
    • Python - Behave
    • C# - NSpec
    • Javascript - Cucumber-js & Jasmine

    View full-size slide

  21. So let’s do this!
    Start small.

    View full-size slide

  22. So let’s do this!
    https://github.com/caseysoftware/is-your-API-misbehaving *
    * I don’t like Github as an organization but didn’t
    have time to convert all of this and fully test it
    with Gitlab which is a better product and company.

    View full-size slide

  23. Using Github…
    24
    • Let’s start with search
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • simple-search-step-{n}-{description}

    View full-size slide

  24. Using Github…
    25
    • Now, let’s get the issues for a repository
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • issues-list-step-{n}-{description}

    View full-size slide

  25. Using Github…
    26
    • Now, let’s get all of your repositories
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • authentication
    • myrepos-step-{n}-{description}

    View full-size slide

  26. Using Github…
    27
    • Now, let’s watch a repository
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • watch-repo-step-{n}-{description}

    View full-size slide

  27. Using Github…
    28
    • Now, let’s fork a repository
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • watch-repo-fork-step-{n}-{description}

    View full-size slide

  28. Using Github…
    29
    • Now, let’s create a repository
    • Write the story
    • Add the stubbed methods
    • Write the methods
    • Validate the results
    • create-repo-step-{n}-{description}

    View full-size slide

  29. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  30. And now what?
    31
    • Write the feature
    • Refactor to reuse steps when possible
    • Add the missing bits
    • GOAL:
    • We should be writing less and less code!

    View full-size slide

  31. Next Steps?
    32
    • We can validate other helper libraries too
    • One set of features/specs for the API using:
    • the PHP library
    • the Ruby Gem
    • the Python library

    View full-size slide

  32. • Assumptions
    • The Problem
    • Enter BDD
    • BDD in Practice
    • BDD at Scale
    • Next steps…

    View full-size slide

  33. todo next?
    34
    Lots of things!

    View full-size slide

  34. todo next?
    35
    But remember:
    Start small and iterate!

    View full-size slide

  35. D. Keith Casey Jr
    [email protected]
    @CaseySoftware
    Is Your API
    Misbehaving?

    View full-size slide

  36. Who am I?
    http://TheAPIDesignBook.com

    View full-size slide