jMock is cool
I have started to work with “jMock in my unit tests”:http://www.jmock.org/index.html. I gotta say that I really like it. The main point of jMock is that it allows you to quickly implement dependencies for a class and then inject those dependencies into the object that you are testing. This allows you to fully isolate your object from the rest of its environment.
I realize that jMock has been around for a while, and I realize that there is some opposition to its use among people in the Java community, but it is new to me and it has definitely affected the way that I go about unit testing my classes. At first it seems a pain to create the mock objects and learn the different method calls, but once you get that, it is really easy to work with.
The only limitation that I have found so far is if you need to implement a dependency that modifies an object that it is given in some way and then returns it to the calling method. On the other hand, I am not sure that code should be doing this anyway. An example of this would be mocking up a Hibernate save() call where Hibernate would inject the primary key into the object once it has been saved to the database (okay, that is probably a bad example as equality should not be based on the primary key, but on the attributes of the object).