Too clever by half!

The Mekon

I recently wrote a simple test framework to use on a project that is using Python on Series 60 phones. I began the project using PyUnit but found the API unintuitive. I wanted something more "pythonic", so I rolled my own.

I was initially puzzled about how to bootstrap the development of the test framework. How could I write the test framework itself test-first? Then I came up with a cunning plan: because I was also writing my project test-first, I could use the project as the test for the test framework that was being used to test the project. A simple, straightforward solution to my dilemma, as I'm sure you'll agree. Maybe.

The way I figured it, I'd write a test in my not-yet-existing test framework that would test my not-yet-existing project. When I first ran the test, it would not report that my project did not behave as expected. Intead it would report that the test framework did not behave as expected. So, I would keep writing the test framework and running the tests until it reported the expected failure of my project. I could then make the tests pass by writing project code, and start all over again until I had a working project tested by a working test framework. Pretty soon the test framework would be complete and I could focus just on the project.

It worked like a charm. I soon had a simple, flexible test framework and well tested project code. But of course, I was missing tests for the test framework itself. As I added features to the framework and built some useful development tools around it (more about those later) other developers started to get interested in the framework and wanted to use it on their projects too. This meant I had to extend the framework with features that my project didn't need and so I could no longer test the test framework against the project and vice versa.

I had to bite the bullet and write tests for the test framework. I hate testing after the fact - it's boring and error prone, but what else could I do? I should have written good tests in the first place instead of being too clever for my own good.

Copyright © 2006 Nat Pryce. Posted 2006-03-17. Share it.

Comments powered by Disqus