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
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
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
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
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
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
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