Hi all,
Just merged in a lovely new unit test from Philip (thanks Philip!), and thought that while I was in the file I may as well spend a couple of minutes converting it from an old-style-client-and-fixture based slow test to a speedier test using our brand new (and still developing) guidelines for writing faster tests (thanks to Sarah). Hopefully this will provide a nice straightforward example of what we're aiming for.
View the
commit to see the changes, and my explanation for each change I made.
This commit sped this one test up from 1.097 seconds to 0.319 seconds, which may not sound like much but scale that up to 160 tests (and more being added all the time) and it would represent a significant speed up over the entire test suite if we were to convert all or most of the tests we have. I can easily make a round of tea while it's running at the moment ... I'd rather my tea drinking were not dictated by the test suite ;D
I propose that for the time being, we try to ensure that new tests conform to these guidelines wherever possible (sometimes you'll need to use the test client for some reason, but I can't see any genuine reason for needing the fixtures). If we also continue to convert old tests as and when we're working on them anyway, then we'll gradually reduce the time it takes to run the suite (which would be great!). One day maybe one of us will have time to systematically go through and convert blocks of tests as well which should give more dramatic results.
Please feel free to ask questions or suggest more improvements.
Cheers!
Jo