Developers have many different options out there to create fast and relatively maintainable unit test suites. But this takes a great deal of knowledge involved in decoupling modules of code, isolating the code under test within its test context, and using test doubles (stubs, fakes, mocks). What's more confusing is that within the concept of doubling itself, there are many different approaches that are vastly different from one another:
- Using dynamic languages/metaprogramming or instrumentation approaches to override implementations of methods (even static methods or initializers) for the duration of a test run.
- Interaction based approaches based on defining expectations and recording expected calls on doubles.
- Using "fake" double implementations provided for testing with a third-party framework you're using.
- Creating your own stubs.
This means while someone may be familiar with the "mock" objects (I prefer to call these fakes) provided by SpringMVC, for instance, some interaction-based mocking code can leave the same person scratching their head. (Is this what happened to Hitler's developers?)
My experience has been (and I suspect others have seen this, too) that very few developers are familiar with this requisite knowledge, and even fewer have enough expertise to develop suites that are somewhat maintainable. (Let's face it, maintainability is a very relative term when we're talking about tests!) Furthermore, often I'll see developers break a test they aren't familiar with and their first instinct is to comment it out rather than fix the test or the code that is broken. Time is often lost in the long-run, but it seems less painful initially.
On your team, how have you dealt with educating and addressing maintenance problems that come about when we don't understand each others' test code?