QCon 2007 Notes: TDD Tutorial

Erik Doernenburg on Test-Driven Development

  • Mostly a basic introduction, though the note that you check in once you’ve got green tests and before you start refactoring (so if it doesn’t work it’s easier to throw it away unscathed), while basic, is still a good reminder
  • “TDD doesn’t mean you can stop thinking”
  • TestDox plugin: automatically creates simple documentation from JUnit class and method names, so:
public class FooTest extends TestCase {
    public void testIsASingleton() {}
    public void testAReallyLongNameIsAGoodThing() {}
}

will be “translated” to:

Foo
- is a singleton
- a really long name is a good thing
  • Recommended Kevlin Henney’s paper (papers) on Five Considerations For Design (economy [i.e. remove to improve], symmetry [but beware of overdoing it], spacing [i.e. separation of concerns], visibility, emergence)
  • NPath complexity: the number of tests required to get complete coverage for all code paths. (McCabe’s cyclomatic complexity counts the number of places the flow branhces; Nejmah’s NPath complexity counts all possible execution paths through a method. Checkstyle can be set up with an NPath complexity limit, and there are also specialized tools like Complexian.)
  • Mocks vs. Stubs rematch: in jMock you can use asserts in custom constraints to get better error reporting, which is cool, or you can use a stub for an even clearer error message, though that can get large and painful. ED notes that both mocks and stubs have their place.
  • Object Mother pattern when you need to create similar test data for multiple tests: rather than repeating stuff in the setup, have a factory (the object mother) that produces the test data
  • Abbot for testing Swing UIs
  • Presentation Model for testing messy GUIs: if you represent the state and behaviour of the GUI in model classes then you can manipulate those directly for testing purposes, bypassing the GUI. So long as you also test the proper binding of your presentation model objects to your GUI, testing the whole becomes much simpler.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply