start with a test

When we write code, it’s a sure thing we’re going to need to execute it. After all, a line that never ran is probably a line that is buggy. You can start with interactive runs from the command line, perhaps with some debug print() s mixed in. But there’s another way to begin.

Start by writing an automated test that calls into your brand new code. Use repeated execution to drive your edit – debug cycle.

What just happened here? You got your tests “for free”!

You’re going to have to do this work anyway. Might as well produce a checked-in document at the same time, which you or teammates can run in the months to come. Give it a try. I predict you’ll like it.

prev next

Copyright 2022 John Hanley. MIT licensed.