Driving Development With Tests

Emily Bache



Test Driven Development is a multifaceted skill, that it takes study and practice to master. In this workshop, we’ll be looking at one particular aspect of it – how to build a piece of code incrementally, driving development with tests. We’ll work in pairs, and do the same code kata problem twice, each time varying the choice of test cases and order to implement them in. Between each coding session we’ll hold a short retrospective, and swap pairs.

The problem we’ll be working on is called “Train Reservation”, and it’s an exercise I’ve specifically designed to need more than one class to implement, and give scope for using mocks and stubs. I’m particularly interested to discuss whether people are working outside-in, and how to use mocks effectively.

The problem comes with some starting code, and a “guiding test” that shows from the outside how to call the new functionality that we’ll be building. I’d like to see how participants choose to use further unit test cases to drive development of the code to the point where the guiding test will pass, and the functionality works.

For the coding sessions I expect participants to choose one of the following three approaches:

  1. Work bottom-up, using unit tests to drive you to build useful parts that you can then fit together in order to make the guiding test pass.
  2. Work outside-in, using fakes to make the guiding test pass, and then add further test cases to drive the fakes to become real production code.
  3. Work outside-in using a London school TDD approach, where you use Mock objects to replace parts you haven’t built yet. You then test-drive implementations of the parts that you’ve previously replaced with a mock.

My hope is that the workshop participants will explore with me how the choice of testing approach can influence design choices, and whether the resultant tests will be maintainable and useful. Beginners to TDD get an introduction to the skill, and more experienced practitioners will have a chance to reflect on how they select test cases, and build a design gradually.

To make it easier to get set up and coding quickly, I have some “starting” code available on github in a range of programming languages: https://github.com/emilybache/ KataTrainReservation. Participants are asked to bring a laptop if possible, and preferably set up the starting code in advance of the session.

Download Slides



Emily Bache has been a software developer and test engineer for nearly 15 years, working in organizations as diverse as small startup and large corporation. These days Emily is an independent consultant specializing in automated testing and agile methods. Emily has recently published a book, “The Coding Dojo Handbook”, based on her work teaching and learning skills like Test Driven Development. Emily has run Coding Dojos at conferences, in companies, with user groups, and has facilitated several Code Retreat events. Emily regularly speaks at international conferences such as XP, Agile Testing Days, ACCU, and currently acts as programme chair for Scandinavian Developer Conference.