To mock or not to mock, that is the question

I'm right now in the final weeks of the first phase of a project. We're very tight on schedule and having to leave a few features for the next phase. Although the project may be delayed because of the client, we want it to be because of them, not us.

One thing that I've done in the project has been using mock objects for simulating an important part of the architecture, a web service which we have to access to do some business logic. This web service has to ve provisioned by the client to us, and because it is a big company, they seem to have delays and lots of approvals before anything important gets done.

So we are nearly 3 weeks before deadline, and we still don't have access to that web service, to the real source. If it wasn't because of the mock-WS I've implemented, we couldn't finish on schedule. I couldn't have coded nearly 50-60% of the really important logic the application needs.

We have frecuent meetings with the client (we're doing XP and specifically Scrum), and they gave us the WSDL and the specification of how the data from the WS will come, so I've mocked it (using a simple ASP.NET Web Service) and right now we haven't goy any problem coding the business logic.

And not only that. By having a mock, I've created some additional commands to enable and disable by specific WS calls things like simulated timeouts, malformed data, missing data and other specific aspects. I've writen tests inside the code that does things like:

  1. Activate timeout
  2. Call the WS
  3. Test if everything went ok and the timeout was catched by the code
  4. Deactivate timeout
  5. Call the WS again
  6. Test if this time data was gathered without problems

While mock objects don't have to be used always and are not "the ultimate salvation", sometimes they become really, really handy, and in my case, critical to reaching all project's requisites (and deadline, I hope ;)

Leverage not just "the extra development time" but the extras they can bring, as better and more deep tests, fast and non-intrusive simulations, and less dependencies on external sources.

Comments?

Posted by Kartones on 2007-08-29