Faking & Mocking

Techniques for Testing Code Safely and Effectively — C Edition

Art for Faking & Mocking Check Out A Preview

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.

Highlights

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

Includes

  • 4-7 hours of content
  • 77 pages of content
  • 11 Interactive quizzes
  • 4 Videos
  • 2 Exercises
  • Platform-independent code
  • Support for Visual Studio
  • Support for Eclipse CDT
  • Uses embUnit

Contents

You Are Here 3
Roll The Dice: A Faking Opportunity 4
This Album 5
Keyword: Awkward Collaboration ← Click to Preview 7
Awkward Results: Indeterminacy 8
Awkward Setup: Ugly Tests 9
Awkward Runtime: Slow = No 10
Awkward Control: Uncontrolled I/O 11
Trust Your Pain 12
Microtesting Awkward Collaborations 14
Real Life Vs. Test Life 15
The Big Idea 16
Types Of Fake 17
Fakes, Roses, And Terminology 18
Aren't You Really Hacking The Code? ← Click to Preview 19
Not Testing All 20
Microtesting Works 21
Slipping In A Fake 23
Keyword: Stub 24
An Awkward Collaboration 25
Awkward Enough For A Stub? 26
Keyword: Talking Fake 27
Example: InventoryControlTalkingFake 28
Taking It One Step Further 29
Keyword: Listening Fake 30
Example: OrderLogListeningFake 31
Refactoring To Facilitate Faking 33
Easy Slip #1: Function Argument Slip 34
Slipping Technique: Parameterize Function 35
Easy Slip #2: Factory Function Argument Slip 36
Slipping Technique: Alternate Factory Function 37
Slipping Technique: Passing A Factory 38
Problem: Several Awkward Collaborators Example 39
Solution: Several Awkward Collaborators Example 40
Link-Time Slipping 41
Compile-Time Slipping 42
Review: Slipping Techniques 43
Introduction 45
The Code 46
Existing Microtests 47
Download The Code 48
The First Case Of Slowness 49
Our Solution 50
Great Microtests 51
Make A Stub For Shipper 52
Slipping A Shipper Stub Solution ← Click to Preview 53
Making a Listening Fake 54
Listening Fake Solution 55
A Little Story 57
What It Looks Like 58
Robin To The Rescue: FakeTransactionLog 59
The Same Test Every Time 60
What To Do? 61
Keyword: Mock 62
Is That All? 63
Big Idea: Interaction, Not State ← Click to Preview 64
Big Idea: Mocks Can Be Made Automagically 65
How Are Mocks Born? 66
A Hardware Situation 68
Keyword: Simulator 69
Simulators In Practice 70
The Real Role Of Simulators 71
Real Objects vs. Fakes & Mocks 73
An Example 74
A Defect Slips Through 75
Conclusion: What's Next? 77

Related Items

Volume Licensing

Have Any Questions?

Highlights

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

Includes

  • 4-7 hours of content
  • 77 pages of content
  • 11 Interactive quizzes
  • 4 Videos
  • 2 Exercises
  • Platform-independent code
  • Support for Visual Studio
  • Support for Eclipse CDT
  • Uses embUnit

Contents

You Are Here 3
Roll The Dice: A Faking Opportunity 4
This Album 5
Keyword: Awkward Collaboration ← Click to Preview 7
Awkward Results: Indeterminacy 8
Awkward Setup: Ugly Tests 9
Awkward Runtime: Slow = No 10
Awkward Control: Uncontrolled I/O 11
Trust Your Pain 12
Microtesting Awkward Collaborations 14
Real Life Vs. Test Life 15
The Big Idea 16
Types Of Fake 17
Fakes, Roses, And Terminology 18
Aren't You Really Hacking The Code? ← Click to Preview 19
Not Testing All 20
Microtesting Works 21
Slipping In A Fake 23
Keyword: Stub 24
An Awkward Collaboration 25
Awkward Enough For A Stub? 26
Keyword: Talking Fake 27
Example: InventoryControlTalkingFake 28
Taking It One Step Further 29
Keyword: Listening Fake 30
Example: OrderLogListeningFake 31
Refactoring To Facilitate Faking 33
Easy Slip #1: Function Argument Slip 34
Slipping Technique: Parameterize Function 35
Easy Slip #2: Factory Function Argument Slip 36
Slipping Technique: Alternate Factory Function 37
Slipping Technique: Passing A Factory 38
Problem: Several Awkward Collaborators Example 39
Solution: Several Awkward Collaborators Example 40
Link-Time Slipping 41
Compile-Time Slipping 42
Review: Slipping Techniques 43
Introduction 45
The Code 46
Existing Microtests 47
Download The Code 48
The First Case Of Slowness 49
Our Solution 50
Great Microtests 51
Make A Stub For Shipper 52
Slipping A Shipper Stub Solution ← Click to Preview 53
Making a Listening Fake 54
Listening Fake Solution 55
A Little Story 57
What It Looks Like 58
Robin To The Rescue: FakeTransactionLog 59
The Same Test Every Time 60
What To Do? 61
Keyword: Mock 62
Is That All? 63
Big Idea: Interaction, Not State ← Click to Preview 64
Big Idea: Mocks Can Be Made Automagically 65
How Are Mocks Born? 66
A Hardware Situation 68
Keyword: Simulator 69
Simulators In Practice 70
The Real Role Of Simulators 71
Real Objects vs. Fakes & Mocks 73
An Example 74
A Defect Slips Through 75
Conclusion: What's Next? 77

Related Items