Unit Testing

Bas Bossink

November 2010

Contents

Introduction

Definitions

see

as dicusssed in Agile Testing

Definitions

Good Unit Tests

Good Economics

see

Bad Economics

see

Good Unit Tests are A TRIP

It ain't a Unit Test when

Test Code Quality

Test Doubles

PatternPurposeHas BehaviorInjects indirect inputs into SUTHandles indirect outputs of SUTValues provided by test(er)Examples
Test DoubleGeneric name for family
Dummy ObjectAttribute or Method Parameternono, never calledno, never callednoNull, "Ignored String", new Object()
Test StubVerify indirect inputs of SUTyesyesignores theminputs
Test SpyVerify indirect outputs of SUTyesoptionalcaptures them for later verificationinputs (optional)
Mock ObjectVerify indirect outputs of SUTyesoptionalverifies correctness against expectationsoutputs & inputs (optional)
Fake ObjectRun (unrunnable) tests (faster)yesnouses themnoneIn-memory database emulator
Temporary Test StubStand in for procedural code not yet writtenyesnouses themnoneIn-memory database emulator

Inspiration

Katacast Uncle Bob Prime Factors

Reality

Excerpt of Billy Hollis interview

Where do we want to go?

Next actions