TITLE: The Tests Are For Me AUTHOR: Eugene Wallingford DATE: August 14, 2010 11:30 AM DESC: ----- BODY: Yesterday, one of my former students tweeted,
"Write a test first." But unit tests are low priority. The business wants high priority items first.
When I asked, "Is correct code a high priority?", he rephrased my question as, "Is proof of correct code a high priority?" I knew what he meant and so dropped the exchange, sad that companies still settle for code without tests in the name of expediency. I try not to be dogmatic about writing tests with code, let alone driving the design with tests, and know there are times when not writing tests, at least now, feels okay. But then it occurred to me. When I write tests, the tests aren't really for "them", whoever "them" might be: my bosses, my colleagues, or my users. My best test suites are the ones I write for myself. They are a part of how I write code. When I'm not doing TDD and not writings tests in parallel with my code -- when not writing tests feels okay -- I am almost always not writing interesting code. Perhaps I know the domain so well that I can write the code with my eyes closed. Perhaps the domain does not engage me enough that I care to get into the deep flow that comes with testing, growing, and refactoring my program. If the task is dull or routine, then tests seem unnecessary, a drag. (Perhaps, though, I especially need to write tests in these situations, to guard against producing bad code as a result of complacency and boredom!) When I am writing code I enjoy, the tests are for me. Saying to me, "Don't take time to write tests" is like telling me not to use version control. It's like saying to me, "Don't take time to format your code properly" or "Don't bother naming your variables properly". Not writing tests seems foreign. Not writing tests is an impediment to writing code at all. It's really not a matter of "taking time to write a test first". I write tests because that's how I write code. -----