This is probably old news to everyone who reads this, but today I had a bit of an epiphany. I was watching Charles Max Wood’s excellent Teach Me To Code Screen-cast and realized (after watching two parts of his “building a blog” series) that he wasn’t ever actually looking at the output of his coding, at least in the traditional sense.
The way I’ve coded since, well, forever has been like this. I open up my editor window, and an output window. When I was writing C code back in the dot com days this was another terminal with a “make && ./app” in it, and in my newer web application days, a browser window with my mouse hand on the reload button. After a bit of code was written, I’d either hit “up-arrow enter” for C code or reload the browser, and see what’s happened.
Watching the screen-cast I realize that Charles was doing the following (as far as I can tell, as I’m pretty new to the whole TDD thing):
Writing a scenario or feature (using cucumber)
Using that to generate tests (with rspec, I think)
Running the test, watching it fail
Writing the code to make the test pass
Running the test, watching it pass
Now the last four steps I do know about, those are standard TDD methodology, broken down into Red (write a failing test), Green (make it pass), Refactor (make the code better), but I was blown away with the realization that he wasn’t looking at the output of the code he was writing, but instead was letting the testing framework do the work, so instead of having to verify with your own eyes that the [insert web page you’re interested in here] is showing properly, you have it checked programmatically, no browser needed (in fact, at the point in part two when the browser is needed, there’s that uncomfortable pause while FireFox groans and raises itself into a running state).
Is that what TDD is really about? I’ve always imagined it as an augmentation to the previously-described way I used to code in that before I coded and reloaded the browser window you’d write the test, then the code, then the browser reload, then the test again to make sure it passed.
This is a whole new world that’s frankly thrown me for a loop, and into a fervor of reading up on cucumber. I’m not sure how this will affect my code writing, but this makes the whole world of TDD a lot more interesting! Course, I’ll have to re-watch the two episodes to make sure I truly grok the tools that he’s using