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

Break Your API: Adapting Unit Testing Frameworks to API Integration Testing by Bonnie Mattson

Break Your API: Adapting Unit Testing Frameworks to API Integration Testing by Bonnie Mattson

More Decks by API Strategy & Practice Conference

Other Decks in Technology

Transcript

  1. Break Your API Adapting Unit Testing Frameworks to API Integration

    Testing Bonnie Mattson | @bonmatts | Software Engineer Context.io | @contextio
  2. Case 1: All the JSON Documents, ever. • A Resftul

    API backed by mongoDB • 500 example json documents
  3. Case 1: All the JSON Documents, ever. • A Resftul

    API backed by mongoDB • 500 example json documents • Verify that basic CRUD operations can be performed on each document
  4. Case 1: All the JSON Documents, ever. • A Resftul

    API backed by mongoDB • 500 example json documents • Verify that basic CRUD operations can be performed on each document • BTW, these documents may change as the specifications for them that are determined by some committee somewhere change
  5. Solution 1: All The Callbacks POST GET POST GET PUT

    GET GET DELETE verify creation create modify part verify mod modify whole verify mod . . . verify delete
  6. Solution 1: All The Callbacks POST GET POST GET PUT

    GET GET DELETE verify creation create modify part verify mod modify whole verify mod . . . verify delete
  7. Case 2: Context.io • Given a set of email account

    credentials, developers can interact with the email account mailboxes in a Restful way.
  8. Case 2: Context.io • Given a set of email account

    credentials, developers can interact with the email account mailboxes in a Restful way. • 2 versions of the api, with ~152 endpoints, ~168 parameters across endpoints, and ~ 2.5 million requests a day
  9. Case 2: Context.io • Given a set of email account

    credentials, developers can interact with the email account mailboxes in a Restful way. • 2 versions of the api, with ~152 endpoints, ~168 parameters across endpoints, and ~ 2.5 million requests a day • TECH DEBT
  10. Case 2: Context.io • Given a set of email account

    credentials, developers can interact with the email account mailboxes in a Restful way. • 2 versions of the api, with ~152 endpoints, ~168 parameters across endpoints, and ~ 2.5 million requests a day • TECH DEBT • Not the canonical data source.
  11. What do we need to do? • Control the data

    source, the mailbox • Set up state before the tests run
  12. What do we need to do? • Control the data

    source, the mailbox • Set up state before the tests run • Prevent state leakage across tests
  13. What do we need to do? • Control the data

    source, the mailbox • Set up state before the tests run • Prevent state leakage across tests • Reuse examples
  14. Solution? Rspec. • Set up state before the test, tear

    it down after • Shared examples to keep it DRY
  15. Solution? Rspec. • Set up state before the test, tear

    it down after • Shared examples to keep it DRY • Readable
  16. Solution? Rspec. • Set up state before the test, tear

    it down after • Shared examples to keep it DRY • Readable
  17. IN CONCLUSION • It is vitally important to break your

    API before your customers do. • There is no “right” way to test your API. Programatic integration test suites using unit testing frameworks is one approach.
  18. IN CONCLUSION • It is vitally important to break your

    API before your customers do. • There is no “right” way to test your API. Programatic integration test suites using unit testing frameworks is one approach. • Use whatever framework you want to.
  19. IN CONCLUSION • It is vitally important to break your

    API before your customers do. • There is no “right” way to test your API. Programatic integration test suites using unit testing frameworks is one approach. • Use whatever framework you want to. • We use a combination of tools to test and monitor context.io, including Runscope
  20. • Shawn Nussbaum, Michael Bernstein, Dan Corbin, Aaron Mills, Bob

    Potter, Eric Pinzur, Susi Rathmann, Ryan Michael, David Lyons, Aaron Labrie, Clare Glinka, Cecy Correra, Sarabjit Singh,Allyson Weber, and Tony Blank for convincing me to submit this talk Thanks