TDD and Mock Objects with jMock 2

Nat Pryce, Romilly Cocking, SteveFreeman and Andy Pols

Introduction to Agile Track
Scheduled Time: 
Tuesday 20 November 2007, 01:30 to 03:00
Scheduled Time: 
Tuesday 20 November 2007, 03:30 to 05:00
Room: 
Glaziers Hall, The Banqueting Hall
Laptop required
Session type: 
tutorial
Intended audience and experience level: 

Developers (any level) Knowledge of Java.

Prerequisites: 

Laptop (including power cable!) Java development environment

Summary

This hands-on tutorial teaches Test-Driven Development and Mock Objects using the JUnit and jMock 2 libraries. We will cover: What is Test-Driven Development? Why is it so widely used in Agile projects? What are Mock Objects and where do they fit into the TDD process? How are tests and Mock Objects used to drive good object-oriented design.

We will touch on: What should, and should not, be mocked? How do you write flexible tests that do not break when you make unrelated changes to the code? How do you use the tests to identify issues with the design and how do you fix those issues?

Programme

We will start by presenting an overview of TDD that addresses the following questions:

  • What is Test-Driven Development?
  • Why is it so widely used in Agile projects?
  • What are Mock Objects and where do they fit into the TDD process?
  • How are tests and Mock Objects used to drive good object-oriented design

The presentation will conclude by describing the scenario that we will use for the pair programming exercise to come.

We will then introduce the jMock 2 API through a live demonstration, writing the first test of the exercise and then just enough code to make it pass.

The participants will then work in pairs to implement the first test for themselves and continue with the exercise. The exercise will be run in iterations. After each iteration the participants will share the lessons they learned with the group and we will present more detailed explanations of the issues raised. The exercise and discussions will answer the following questions:

  • What should, and should not, be mocked?
  • How do you write flexible tests that do not break when you make unrelated changes to the code?
  • How do you use the tests to identify issues with the design and how do you fix those issues?

We will wrap up the session with a further presentation reiterating the lessons learned and looking at them in more detail, with good and bad code examples.

Nat Pryce

This presenter hasn't provided a bio yet.

Romilly Cocking

This presenter hasn't provided a bio yet.

SteveFreeman

Steve is a pioneer of Agile software development in the UK, he has built applications for banks, ISPs, financial data providers, and specialist software companies. He has given training courses in Europe , America, and Asia. Previously, he worked in research labs, software houses, earned a PhD, and wrote shrink-wrap software. Steve has also taught at University College London. He is a presenter and organizer at international industry conferences, and was conference chair for the first London XpDay.

Andy Pols

Andy is a software-requirements and agile-delivery expert. He runs Pols Consulting, a company helping clients focus on what’s important - understanding the business value of what they do. Ultimately, he helps teams cut through the haze and deliver quality products. He is a co-author of “Patterns for Effective Use Cases”, writer of numerous articles, a regular speaker at conferences, a founder member of the “Highgate Guild” and a regular at London’s Extreme Tuesday Club. Andy is based in the UK with a worldwide client base.

You can find my blog at www.pols.co.uk/blog