Mocks, Fakes and Stubs
Mocks, Fakes and Stubs
$5.99
Minimum price
$10.00
Suggested price
Mocks, Fakes and Stubs

This book is 25% complete

Last updated on 2013-12-03

About the Book

If you're interested in improving your practice at programming in general, and Test Driven Development in particular, I'd suggest doing code katas is a good way to learn. There's a host of programmers around the world using code katas to hone their skills and learn from one another, in a coding dojo, at a code retreat, in a pair on a lunchbreak, or just by themselves. This book uses Code Katas to illustrate some modern coding techniques, so you can learn about, and practice them.

A code kata is a simple coding problem that may take a little effort to solve the first time, but the point is you don't only do it once. Start over from scratch and try it again, but think more carefully about how you're solving it. Can you work in small steps, refactoring often, and keep your design simple and clean? Can you write a good suite of automated tests that support your development and provide good regression protection for future maintenance work? The challenge in a Code Kata is to solve the problem well, and to demonstrate good practices in how you reach your solution. If you're using Code Katas like this, you'll find you build up a repertoire of katas that you know well, and can use to polish your coding technique.

Code Katas are also useful when you're trying out something new - a tool, technique or coding environment. Keep one variable the same - the problem to solve - and see how your coding experience, design, and tests are affected by the new element. It's this way of using Code Katas that is the focus of this book. I'm assuming you are familiar with each code kata, and can use it to show you a new technique.

In this book I'll show you examples including, but not limited to, Mocks Fakes and Stubs. I'll also discuss techniques like London School TDD, Outside-In development, and Approval testing. I'll begin each topic with a discussion of the theory, and follow it up with some code listings and sample tests. My aim is that it'll be a little like pair programming with someone experienced in the technique, who can explain what they mean both in theory and example, and give you some commentary about when you might choose to use it. You'll definitely be expected to put in some work yourself, learning the Code Katas, and trying the techniques out for yourself. It'll certainly be more fun if you can get a group together and start a Coding Dojo.

My first book, "The Coding Dojo Handbook", is full of practical advice about how to set up this kind of a space for learning. While I was working on that book, I found myself writing long passages about particular techniques, and how you could learn about them using some of the code katas listed in the catalogue in that book. In the end, I decided that material didn't belong in "The Coding Dojo Handbook", and that it would be better to start a new book.

The techniques in "Mocks, Fakes and Stubs" are all useful to practice in a Coding Dojo environment, but not exclusively. I've included examples taken from a range of programming languages, including Java, Python, C++ and C#. You can do a Code Kata in pretty much any language you feel like, and you'll find and starting code is available in many popular languages on my Github page. All the code katas used in this book are listed in the Kata Catalogue from "The Coding Dojo Handbook".

About the Author

Emily Bache
Emily Bache

Emily Bache is a software developer with an interest in community and lifelong learning. She has delivered working software with tests while working in organizations as diverse as small startup and large corporation. These days Emily is a consultant with Praqma, specializing in automated testing. Her blog is called "Coding is Like Cooking". Emily is originally from the U.K. but now lives in Göteborg, Sweden.

Bundles that include this book

The Coding Dojo Handbook
Mocks, Fakes and Stubs
2 Books
$35.00
Suggested Price
$23.00
Bundle Price

Table of Contents

  • Introduction
  • Acknowledgments
  • How to Read This Book
  • Code Kata
    • Two kinds of practice
  • Unit Testing Basics
    • What is an automated unit test?
    • Unit Testing explained with a simple example
    • Test Case Design
    • Conclusions
  • Test-Driving an Algorithm
    • Stress Testing
  • Test Doubles
    • Example with a Stub
    • Example with a Fake
    • Example with a Mock
    • Example with a Test Spy
    • Using an isolation framework for Mocks and Spies
    • Example with a Dummy object
    • Why use test doubles?
    • Using Meta-Programming to insert test doubles
  • Double-Loop TDD
  • The London School of TDD
    • Classic vs London School
    • Designing Outside-In
    • Outside-In, With London School TDD
    • “Tell, Don’t Ask” Object Oriented Design
    • Mocks used badly
  • Outside-In example (not written yet)
  • Tell, Don’t Ask example (not written yet)
  • London School TDD illustrated (not written yet)
  • Approval Testing
    • Minesweeper example
    • The Golden Master
    • Tools for Approval Testing
    • Legacy Code
  • Other Techniques that I havn’t decided on yet
    • Ideas
  • Further Reading

Other books by this author

The Leanpub 45-day 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Write and Publish on Leanpub

Authors, publishers and universities use Leanpub to publish amazing in-progress and completed books and courses, just like this one. You can use Leanpub to write, publish and sell your book or course as well! Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks. Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. It really is that easy.

Learn more about writing on Leanpub