lowering impedance of TDD with python mock

So after my post about gaeunit a few weeks ago I've since completely thrown out what I was doing there and moved to vanilla python unit tests. I ended up making this move for a few reasons.

 1. I was never running my tests.
  • GAEUnit was nice, but slow. Even when running tests in parallel I still had to go through the process of opening the browser, navigating to the right place and letting the tests run. Compare this to ctrl-f9 and seeing the following:  

 2. AND I love seeing code coverage numbers and while it might actually be possible with GAEUnit, it wasn't this easy...

In the end it was relatively simple once I started employing mocking to deal with sessions and realized that I could actually issue real request objects to my handlers with relative ease... 

    webObReq = Request.blank(url)
    webApReq = webapp.Request(webObReq.environ)
    handler.initialize(webApReq, webapp.Response())

For the mocking I eventually decided to go with this framework:
It has so far been fine for my needs and at least my handlers have almost achieved 100% coverage. The syntax is a little foreign compared to Moq, but hasn't been a blocker to me actually getting work done so I'd recommend it.  

1 comment:

  1. Hey - I shared a similar frustration with gaeunit testing until I managed to integrate it with junit formatted output and then put the source tree in a CI engine (hudson). Now, I don't ever both running a whole suite of tests - just the ones relevant to the code at hand and when I checkin ... Boom, test reports etc etc all auto generated for me. Oh and happy sun icons too !