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

Clean Tests

Noam Almog
February 24, 2017

Clean Tests

Clean test presentation,
Kiev JUG, 23.2.17

Noam Almog

February 24, 2017
Tweet

More Decks by Noam Almog

Other Decks in Programming

Transcript

  1. Should I Clean ? § Test lasts More than production

    Code. § More Lines of code § Read and reviewed More
  2. If you let the tests rot, then your code will

    rot too “ “ Robert C. Martin
  3. What Is ”Good” ? § How easy is it to

    extend it ? § When break, is it easy to fix ? § How many “Rewrite” calls ?
  4. Test Structure § Test is a Map to your code.

    § Reveille the right amount of details. § Should be Consistent (*)
  5. Test Description § Use Plain English § Use Simple Language

    – Not Code ! § Find a sentence structure § “throw an exception if user does not exist” § “send an email to the the email registered with the site-id”
  6. Extract Setup to Methods § Select method name that implies

    structure § Starts with given § Contain the collaborator name § Describe the defined Behavior § Reverse the order of parameters § Use parameter names to show what is important
  7. Simplify The Code § Do not use concrete values in

    the test. § Reduce number of moving parts § Do not move important logic out of the scope
  8. Extract Drivers § Move all setup method to it §

    Move all related variables to it § Split according to the Subject
  9. Match Expectations § Use just one matcher § Describe what

    you are matching, now how § Don’t define any new variables
  10. Conclusion § Test behavior and not code § Test Should

    stand on his own § Describe what and not how § Start today, don’t wait for tomorrow § Use only variables you defined