Unit tests I love thee
Wednesday, April 21st, 2010So we pushed out Zeitgeist 0.3.3. I was hacking on a bug where we’d at times be notifying monitoring applications of deletions even if someone tried to delete an non-existing event from the log. When I landed my fix I only discovered that I had broken one of the unit tests (I swear I tested this before I landed my branch!
). Apparently one could no longer delete events with timestamp 0.
Just when I realized this I was going “Yuk! Because of this far out corner case I have to change my code from something beautiful an simple to something ugly”. Concretely I just had a if all(timestamps): do_stuff(), but since timestamps can be 0 I had to manually check the list. However as I was fixing my code I realized just how wonderful this was. That our testing suite even caught exotic stuff like this. Firstly events with timestamp 0 are events that would have happened 40 years ago. Secondly deletions are rare. But in any case – it’s wicked cool that we caught this in the tests. It really demonstrates the awesomeness of a comprehensive test harness. Way to go team!