By Mike Hill, Gil Broza

How do you write microtests against old, complicated code? Redesigning the code can help, yet often you'll still need to deal with awkward collaborators: calls to objects that are slow or difficult to test. Vanquish awkward collaborators by learning a family of fakes, including simulators, stubs, listening and talking fakes, mocks and auto-mocks.



Get this Album

Volume Licensing

Have Any Questions?

Highlights

Expert Videos: Learn tools & techniques by watching short videos from industry experts. Learn more...
Integrated Forums: Ask questions, get expert replies and read fascinating discussions. Learn more...

Includes

  • 4-7 hours of content
  • 146 pages of content
  • 11 Interactive quizzes
  • 4 Videos
  • 3 Exercises
  • Coverage of gMock
  • Platform-independent code
  • Support for Visual Studio
  • Support for Eclipse CDT
  • Uses Google Test

Contents

You Are Here 3
Roll The Dice: A Faking Opportunity 4
This Album 5
Awkward By Domain: The Maker & The Dice 7
One Weak Microtest 8
The Goal 9
Steps For The Exercise 10
Download the Code 11
Our Solution 12
Key Points For Your First Fake 13
Roll The Dice Fakelessly 15
Steps For The Exercise 16
Download the Code 17
Our Solution 18
Points To Ponder 19
Intro to Auto-Mocking 21
Steps For The Exercise 22
Some Details for the Automocker 23
Download the Code 24
Our Solution 25
Points To Ponder 26
Keyword: Awkward Collaboration ← Click to Preview 28
Awkward Results: Indeterminacy 29
Awkward Setup: Ugly Tests 30
Awkward Runtime: Slow = No 31
Awkward Control: Uncontrolled I/O 32
Trust Your Pain 33
Microtesting Awkward Collaborations 35
Real Life Vs. Test Life 36
The Big Idea 37
Types Of Fake 38
Fakes, Roses, And Terminology 39
Aren't You Really Hacking The Code? ← Click to Preview 40
Not Testing All 41
Microtesting Works 42
Slipping In A Fake 44
Keyword: Stub 45
An Awkward Collaboration 46
Awkward Enough For A Stub? 47
Keyword: Talking Fake 48
Example: InventoryControlTalkingFake 49
Taking It One Step Further 50
Keyword: Listening Fake 51
Example: OrderLogListeningFake 52
The Relationship Between Fake And Awkward ← Click to Preview 53
Refactoring To Facilitate Faking 55
Easy Slip #1: Method Argument Slip 56
Slipping Technique: Parameterize Method 57
Easy Slip #2: Constructor Argument Slip 58
Slipping Technique: Alternate Constructor 59
Slipping Technique: Passing A Factory 60
Several Awkward Collaborators Example: Problem 61
Several Awkward Collaborators Example: Solution 62
Slipping A Fake, Dependency Injection and Inversion Of Control ← Click to Preview 63
Slipping Technique: Introduce Adapter 64
Introduce Adapter Example 65
Adapter in Pictures 66
Slipping Technique: Templatize Collaborator Type 67
Templatize Collaborator Type Example ← Click to Preview 68
Would You Use This Technique? 69
Review: Slipping Techniques 70
Introduction 72
The Code 73
Existing Microtests 74
Installing Our Plugin 75
Download The Code 76
The First Case Of Slowness 77
Our Solution 78
Great Microtests 79
Make A Stub For Shipper 80
Slipping A Shipper Stub Solution ← Click to Preview 81
Making a Listening Fake 82
Listening Fake Solution 83
Our Love/Hate Relationship With Singletons 85
Problems With Singletons 86
So, No Static Objects? 87
Solutions to Singletons 88
Slipping Technique: Alternate Construction 89
Slipping Technique: Set Fake Singleton 90
Set Fake Singleton Example ← Click to Preview 91
Slipping Technique: Redirection 92
Redirection Example 93
Static Collaborator: Another Example 94
Static Collaborator: Possible Solution 95
Exercise: Faking A Singleton 97
A First Attempt 98
Installing Our Plugin 99
Download The Code 100
Double Awkwardness 101
Hints 102
Our Solution 103
A Little Story 105
What It Looks Like 106
Robin To The Rescue: FakeTransactionLog 107
The Same Test Every Time 108
What To Do? 109
Keyword: Mock 110
Is That All? 111
Big Idea: Interaction, Not State ← Click to Preview 112
Big Idea: Mocks Can Be Made Automagically 113
How Are Mocks Born? 114
What are Auto-Mocks? 116
Five Steps To gMocking 117
A Video Introduction to gMock 118
Quick Reference: The Method Declaration Syntax 119
Quick Reference: The ON_CALL Syntax 120
Quick Reference: The EXPECT_CALL Syntax 121
Yowza! 122
Let's Play 'Find The Mock' 123
Quick Reference: Exact Parameter Matching 124
Quick Reference: Matchers 125
Quick Reference: Sequences 126
Quick Reference: Actions 127
Automocking Expectations 129
The Challenge 130
The Code 131
Awkwardness ← Click to Preview 132
Download The Code 133
Your Mission 134
The Simplest Case 135
The Second Task 136
Solution For The Second Task 137
The Last Task 138
Solution For The Last Task 139
A Hardware Situation 141
Keyword: Simulator 142
Simulators In Practice 143
The Real Role Of Simulators 144
Conclusion: What's Next? 146

Related Items

Supported Browsers

  • Latest Firefox
  • Internet Explorer 8+
  • Latest Chrome
  • Latest Safari

Operating Systems

  • Windows
  • Linux
  • Mac OS X

Development Tools

You can use whatever developments tools you prefer. If you do use an IDE (Integrated Development Environment), many (though not all) of our labs come with projects pre-configured for Eclipse, IntelliJ and Visual Studio.

Speakers or headphones are required for our videos.

Flash is required to view charts or watch videos — download for free.