My chapter in Beautiful Code is called "Beautiful Tests". In the chapter, I focus on a specific example of how a developer can use tests to make the code not only more robust, but also more beautiful.
I really enjoyed sharing my thoughts, and thought-processes, on developer testing using lots of actual code on a very specific example. But, as I was writing this chapter, I kept feeling a strong urge to also write something at a higher-level; something a bit more general and philosophical, to complement it.
The result is The Way of Testivus - Less Unit Testing Dogma, More Unit Testing Karma, a small booklet with twelve epigrams that summarize my philosophy on developer/unit testing.
Below are two of the epigrams; if you want to read more you can download the entire "The Way of Testivus" booklet.
If you write code, write tests
The pupil asked the master programmer:
“When can I stop writing tests?”
The master answered:
“When you stop writing code.”
The pupil asked:
“When do I stop writing code?”
The master answered:
“When you become a manager.”
The pupil trembled and asked:
“When do I become a manager?”
The master answered:
“When you stop writing tests.”
The pupil rushed to write some tests. He left skid marks.
Think of code and test as one
When writing the code, think of the test.
When writing the test, think of the code.
When you think of code and test as one,
testing is easy and code is beautiful.


Comments (4)
Amen! I tried to get at some of this in my chapter too, and while I was speaking from the stress-testing perspective, the lesson is very much the same. I'm appreciating another advantage of this at the moment: I have a rather large and reasonably new body of code that I have decided to Massively Rewrite. (Specifically, in a different language.) The tests that I wrote as part of the initial implementation are now serving an invaluable role in assuring that my rewritten code is functionally correct. It's somewhat paradoxical -- that the act of being more conservative and writing more tests actually allows one to be much more revolutionary in terms of the scope of future change...
Posted by Bryan Cantrill | August 2, 2007 6:20 PM
Nicely done, Alberto! Thanks again for your contributions to this most crucial of topics.
Posted by Brett Adam | August 9, 2007 9:03 AM
Beaut!
Good work, guys!
Posted by EverShine | August 9, 2007 11:40 AM
This is a great document, and funny too. I sent it around to my team and they thought it was very cool. Great job!
Posted by Justin Bailey | August 14, 2007 3:03 PM