TDD and mock objects

If you are new to TDD and to mock objects (like me) you may want to read the paper “Mocks Aren’t Stubs” written by Martin Fowler. In this article Fowler talks about the two testing paradigms, state based and interaction based.

I will use TDD, for the first time, in my next project and I am thinking to choose between easymock and jmock. I like easymock because you set the expectations in a type safe way that allows refactoring with IDE support and auto complete while editing. On the other hand I like jmock because it seems to be more flexible for setting the expectations and because I like the concept of assertThat() (unit testing with constraint objects instead of assertions) introduced by Joe Walnes in his blog.

I don’t know if I will use the interaction based testing since I don’t like the fact that it couples the tests to the implementation. I will surely use the mock toolkit to create stubs for various services, like DAOs and mail abstractions, since it will allow me to test the middle tier without having to configure external systems like databases and mail servers.