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

The Test Smell Before Christmas

omissis
December 15, 2018

The Test Smell Before Christmas

A small presentation about test smells I gave to open the Drupal Community Day 2018 in Turin, Italy.

omissis

December 15, 2018
Tweet

More Decks by omissis

Other Decks in Programming

Transcript

  1. T H E T E S T S M E

    L L B E F O R E C H R I S T M A S
  2. T E S T S S M E L L

    B U T T H A T O F F E R S G O O D I N S I G H T S O N T H E C O D E Code smells Behaviour smells Project smells
  3. H A R D T O T E S T

    C O D E SYMPTOMS • some code is inherently difficult to test (GUI, threads, remote services) • tight coupling • private logic • lots of dependencies
  4. H A R D T O T E S T

    C O D E IMPACT • testing becomes very hard and time consuming • less tests will be written • does not scale
  5. H A R D T O T E S T

    C O D E POSSIBLE SOLUTIONS • learn to decouple code • separate logic from the async mechanism • keep test logic unconditional
  6. O B S C U R E T E S

    T S SYMPTOMS • no communication of intent • hard to understand • hard to maintain • can hardly be used as docs
  7. O B S C U R E T E S

    T S CAUSES • too much information (eg: Eager test, Irrelevant Information) • too little information (eg: Mystery Guest) • lack of attention and care
  8. O B S C U R E T E S

    T S EXAMPLE: EAGER TEST • symptom: verifies too much functionality in a single test • cause: “mocks” a human doing a test, chaining lots of actions together • solution: create multiple, single-condition tests for better Defect Localisation
  9. O B S C U R E T E S

    T S MYSTERY GUEST • symptom: hard to see cause-effect relationship between input and expected outcome • cause: tests become harder to follow and more fragile • solution: setup inline, aided by helpers/builders
  10. C O N D I T I O N A

    L T E S T L O G I C SYMPTOMS • presence of control structures in tests • some test code doesn’t get executed
  11. C O N D I T I O N A

    L T E S T L O G I C IMPACT • harder to write correct tests • maintenance overhead • decreased confidence in tests • increased chance of bugs in tests
  12. C O N D I T I O N A

    L T E S T L O G I C CAUSES • handling failure conditions • testing collections • testing conditional logic • optimising setup/teardown logic
  13. C O N D I T I O N A

    L T E S T L O G I C POSSIBLE SOLUTIONS • support substitutable deps • add guard assertions • define test-specific equality • enumerate inputs and outputs
  14. C O N D I T I O N A

    L T E S T L O G I C C O D E E X A M P L E