Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Contract testing: Beyond API functional testing

100 views

Published on

Automation guild 2020 conference talk

Published in: Engineering
  • Be the first to comment

Contract testing: Beyond API functional testing

  1. 1. Contract testing: Beyond API functional tests Gaurav Singh
  2. 2. Hi 👋🏼 I’m Gaurav Singh 🏼🏼 Test automation 🏼 at Gojek, Bangalore Full stack tester …. (mobile 📱, web 🏼, backend 🏼) Find me on below: • https://automationhacks.blog/ • https://www.linkedin.com/in/automationhacks/ • https://twitter.com/automationhacks • https://github.com/gaurav-singh • https://stackoverflow.com/users/5336432/gaurav-singh
  3. 3. Learning goals • What is consumer driven contract testing? • What problems does it solve over integration tests? • Understand it’s nuts and bolts ⚙️ • Implement a contract test for a twitter like API using PACT framework with JVM • When not to use? 🏼
  4. 4. Let’s get started. Shall we? 😇
  5. 5. What are consumer driven contract tests?
  6. 6. Consumer driven contracts 🏼 • Confirms contract between a consumer and provider (called Pact) 📃 • Written from the consumer’s perspective 📲 🏼 🌍 • Allows testing them in isolation • Supports testing HTTP, message queues
  7. 7. Example AUT: Twitter API Select “Run in postman” to import the collection in desktop client
  8. 8. Let’s run through a test scenario • Login as a user and get login token
  9. 9. But first a bit of terminology 😇 • Consumer • Provider • Contract • Interaction • Broker
  10. 10. Consumer • Any component that initiates an HTTP request to a provider • Some Examples: • Web or mobile app frontend • Another service • Desktop Client
  11. 11. Provider • Component that responds to the HTTP request • Might have multiple HTTP endpoints as part of the micro-service (CRUD operations) • A single deployable unit
  12. 12. Interaction • Request • Response expectations 💡Note: A Pact file is a collection of interactions in JSON format
  13. 13. Broker • Keeps all the captured PACT’s • Allows the provider to run its checks independently across different projects
  14. 14. How does contract testing work?
  15. 15. Tests consumer first • Checks if consumer generates correct request • Checks if it can handle the different responses from the mock provider
  16. 16. Test provider • Driven entirely by PACT framework • Sends actual request to provider • Compare the actual response to minimum expected response (described in interaction)
  17. 17. Talk 🏼 is cheap. Show me the code 👨🏼💻
  18. 18. If all you have a hammer… • Dos • Check minimal shared understanding of what the provider should return to us. • Works best if you/your org/partner org are developing the consumer and provider • Dont’s • Write to substitute all functional integration tests (don’t check side- effects) • Use it for performance and load testing • To Test Pass through APIs
  19. 19. Not convinced? • Read this link
  20. 20. For further meditation ☯ • GitHub code sample • Pact • Twitter API • Provider states • Pact best practices • Effective pact setup guide • Another JVM example • JVM consumer Junit 4 • JVM provider
  21. 21. Thanks for your attention 🙇🏼 ♂️ Questions?

×