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

How To Write Great Unit Tests

MarcL
July 13, 2017

How To Write Great Unit Tests

How do you learn to write great unit tests? Why are some unit tests good and some bad? Here I talk about 7 tips for writing great unit tests and gaining confidence in your code.

MarcL

July 13, 2017
Tweet

More Decks by MarcL

Other Decks in Technology

Transcript

  1. www.marclittlemore.com MARC LITTLEMORE 7 TIPS FOR WRITING GREAT UNIT TESTS

    www.marclittlemore.com @marclittlemore github.com/marcl
  2. WHY DO WE NEED UNIT TESTS? AIDS IN REFACTOR If

    tests pass then developer refactor has not changed functionality
  3. GOOD TEST NAMES “add expected tax to purchase price” “should

    increase balance when deposit is made” “should set username to null when user is not signed in”
  4. WHY DO WE NEED UNIT TESTS? 1. What is being

    tested? 2. What should the code do?
  5. WHY DO WE NEED UNIT TESTS? 3. What is the

    actual output? 4. What is the expected output?
  6. 7 TIPS FOR WRITING GREAT UNIT TESTS 1. MAKE TEST

    NAMES UNDERSTANDABLE 2. ISOLATION OF DEPENDENCIES 3. ONE REASON TO FAIL 4. MAKE TESTS FAST 5. INDEPENDENT OF ENVIRONMENT 6. TEST UNITS COMPLETELY 7. MAKE TESTING EASY
  7. IMAGE CREDITS Digital background image - Designed by Freepik All

    other images - CC0 from Unsplash or Pexels