I’ve been reading a lot about mocks lately. A couple of good articles from Uncle Bob, in particular When to Mock and The Little Mocker. I’m not very good at employing mocks so these articles have been enlightening. There is a lot I want to apply and grow my skills.
One thing I saw in these articles, and hear consistently from my peers is that without employing these strategies testing against web servers is too slow to be viable. I don’t feel that’s an absolute truth. If the situation is right it can be done. Here’s how it can work.
I worked a project were the servers were pretty light weight java servlets that dispatched JSON RPC requests. We started with various levels of mocking but then we tried a different technique. Using embedded Jetty we fired up the servlets right in process. Real fakes. The servlets were light weight, and started quickly, and the tests hit the end points in process. They ran fast and saved us a lot of effort trying to mock implementations, and make sure those implementations stayed up to date. When the servlet changed, you immediately knew how that effected the contracts because the tests were testing the latest and greatest.