Tutorials
Test-Driven Development
This tutorial demonstrates the development of a small example application using test-driven development and related technologies. The system will comprise a handful of Java classes that exemplify typical components found in enterprise applications, including domain objects and a service layer. The tutorial is structured into three ‘iterations’ which cover
- state-based testing with JUnit
- interaction-based testing with JUnit and jMock
- the ObjectMother pattern and lightweight containers
The iterations not only introduce the concepts but also provide room for the discussion of trade-offs and edge cases, e.g. how to deal with testing private methods and when not to use dynamic mocks but hand-crafted stub objects. The implementation will make use of the Dependency Injection pattern and the last iteration examines how this is supported by lightweight containers.
Attendees gain an understanding of how proper use of test-driven development fosters good design; through decoupling and interface discovery for example. Attendees will also gather a nice catalogue of the most commonly used patterns used in conjunction with test-driven development.
History:
- JAOO 2008 Australia - Sydney, Australia - with Martin Fowler
- JAOO 2008 Australia - Brisbane, Australia - with Martin Fowler
- JAOO 2007 - Århus, Denmark - with Martin Fowler
- QCon 2007 - London, UK - with Martin Fowler
- ØreDev 2006 - Malmö, Sweden - with Martin Fowler
- JAOO 2006 - Århus, Denmark
- JavaZone 2006 - Oslo, Norway
- SI-SE 10th Anniversary Symposium - Zurich, Switzerland - with Aslak Hellesøy
Links:
- Mocks aren’t stubs by Martin Fowler
- xUnit patterns
- Mock Objects wiki
- Object Mother
Recommended reading
If you want to delve further into this topic we recommend the following two books:
Test-Driven Development
by Kent Beck
The ‘original’ book on test-driven development. Part I gives a detailed introduction into the topic and part II shows advanced techniques by implementing a unit testing framework using a test-driven approach.
Domain Driven Design
by Eric Evans
A great book that covers ‘the other half’ of an agile project. It explains how it is possible to build domain models for complex domains during implementation; and why it is in fact benefitial to not create an abstract (logical) model upfront. Also presents many patterns and addresses strategic design.