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

Frisby.js: BDD For Your REST API

vlucas
June 09, 2012

Frisby.js: BDD For Your REST API

Frisby.js is a REST API testing framework built on node.js and Jasmine that makes testing API endpoints easy, fast, and fun. Use Frisby to step in the shoes of your developer community and ensure consistency in API response structures, keys, and types. Great for ensuring your APIs don’t change or break across versions, and remain reliable and consistent so your developer community can thrive.

vlucas

June 09, 2012
Tweet

More Decks by vlucas

Other Decks in Programming

Transcript

  1. Who are You? • Vance Lucas • http://vancelucas.com • @vlucas

    (for heckling) • Brightbit • http://brightb.it • Design, Development & Consulting for web apps, mobile apps and APIs
  2. What is Frisby.js? • Firsby.js is a JSON REST API

    testing tool written in JavaScript using Jasmine and node.js • npm install frisby • API Docs: http://frisbyjs.com/ • Fork me: https://github.com/vlucas/frisby
  3. Why Make Frisby.js? • Developed for a Brightbit client during

    a major API code refactoring • Needed to ensure unmodified API outputs were the same in both old & new versions • Needed to ensure apps would not break • Client’s production API traffic • 2k+ req/s baseline (24/7) • 4-5k req/s peak
  4. BDD is driven by business value; that is, the benefit

    to the business which accrues once the application is in production. The only way in which this benefit can be realized is through the user interface(s) to the application, usually (but not always) a GUI. http://en.wikipedia.org/wiki/Behavior_Driven_Development
  5. Frisby.js Can... • Ensure that your API is working (with

    seamless integration into Continuous Integration tools like Jenkins, etc.) • Check return values • Check return types and object structures • Test your full stack instead of just code • Act as basic developer API documentation • Help users report bugs with code
  6. Full Stack Testing • See and use your own API

    from the perspective of your developers • Test through the caching layer - enables tests for cache invalidation issues • Encourages you to setup a proper test/ development environment (to not create and delete real items via your API)
  7. Bug Reporting • Put your Frisby tests in an a

    public GitHub repository & share the URL • Developers can fork your repo, enter their auth details, and run the API tests • You may want a test/dev (non-production) API url for this • Developers can submit pull requests to report bugs in your API with Frisby tests • You can review, fix the issue, and merge in their code to prevent regressions
  8. Helpers / Config • globalSetup • setup • reset •

    timeout • addHeader • removeHeader • setHeaders • auth • after / afterJSON • get / post / put / delete • create / toss
  9. Expectations • expectStatus • expectHeader • expectHeaderContains • expectJSON •

    expectJSONTypes • expectBodyContains • expectJSONLength • expectMaxResponseTime