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

Renee Chu - Unit Tests, Cluster Tests: A Compar...

Renee Chu - Unit Tests, Cluster Tests: A Comparative Introduction

You've worked on a shared code base and contributed software tests. Great job! But you don't yet know how to set up the holy grail: Having test coverage that's so complete, you can sleep easy knowing any mistake is caught and spoken for. This talk is a "102" level of test talks, describing the different layers of test protection (unit and cluster) and how to approach writing each.

https://us.pycon.org/2016/schedule/presentation/2182/

PyCon 2016

May 29, 2016
Tweet

More Decks by PyCon 2016

Other Decks in Programming

Transcript

  1. This talk is relevant to you if you are: •

    Experienced writing software tests
  2. This talk is relevant to you if you are: •

    Experienced writing software tests • Have not yet owned a project and set up a test suite
  3. This talk is relevant to you if you are: •

    Experienced writing software tests • Have not yet owned a project and set up a test suite “Testing 102”
  4. What does Pwitter do? GET http://pwitter.com/ {username}/tweets See a user’s

    tweets POST -u {user_id}: {auth_token} -d body=”hello world” http://pwitter.com/ {username}/tweets Make a new tweet
  5. What qualities does Pwitter need to have? • Reliability ◦

    Guaranteed Uptime ▪ ie: 99.999% availability (~5min downtime per year)
  6. What qualities does Pwitter need to have? • Reliability ◦

    Guaranteed Uptime ▪ ie: 99.999% availability (~5min/year) ◦ No bugs ▪ ie: a POST to User A’s account shouldn’t add a tweet to user B.
  7. Integration Points Auth Service Geo Service { ‘username’: ‘reneighbor’, ‘date_created’:

    ‘12-12-2015’, ‘user_id’: 10011’, } { ‘name’: ‘portland’, ‘dateCreated’: 1230768000, ‘longitude’: 41.51, ‘latitude’: 127.67, ‘id’: 55505 }
  8. GET “/users/{username}/tweets” 1) Look up user in DB by username

    2) Use user’s ID to fetch tweets 3) Create an empty list of results 4) Loop through tweets and append each tweet to it Unit Tests: Through coverage
  9. GET “/users/{username}/tweets” 1) Look up user in DB by username

    a) If DB fetch fails, raise error b) If no user found, raise error 2) Use user’s ID to fetch tweets a) If DB fetch fails, raise error 3) Create an empty list of results 4) Loop through tweets and append each tweet to it Unit Tests: Through coverage
  10. GET “/users/{username}/tweets” 1) Look up user in DB by username

    a) If DB fetch fails, raise error b) If no user found, raise error 2) Use user’s ID to fetch tweets a) If DB fetch fails, raise error 3) Create an empty list of results 4) Loop through tweets and append each tweet to it Unit Tests: Through coverage Test Cases 1. If DB fetches fail, error is thrown 2. If no user is found, error is thrown 3. If no tweets are found, result with an empty list is returned 4. If many tweets are found, result with correct number and content of tweets is returned
  11. Practical Notes: Where are tests located? • Unit tests: Within

    same code repo as service code • Cluster Tests: Seperate repo, seperate box
  12. Practical Notes: When are tests run? • Unit tests: before

    merging in new code • Cluster tests: continuously
  13. Closing pragmatic advice: • Don’t let the perfect be the

    enemy of the good • Too many tests is (almost) as bad as too few tests