1 The Way of Testivus Less Unit Testing Dogma More Unit Testing Karma Good advice on developer and unit testing, packaged as twelve cryptic bits of ancient Eastern wisdom. Translated by Alberto Savoia
3 Translator s Introduction In May 2006, an ill-prepared international expedition to the Himalayas lost its way. After two weeks of wandering around hungry, thirsty, and smelling like inexperienced expeditioners who got lost for two weeks they stumbled upon an ancient cave. Inside the cave they saw a maze of cubicles. Each cubicle had a wooden desk, an ergonomically correct bamboo chair, a Dilbert calendar, and a strange computer-like mechanical device. In one corner of the offi ce they found barrels of dark liquid (later identifi ed as early examples of a carbonated and highly caffeinated drink) and a pingpong table. They realized that the cave was an ancient software start-up. The oldest one on record. Older even than Netscape. Among the many surprising things they discovered inside the cave was the most amazing one of all: a note left by one of the programmers. The expedition s guide, while not very good at guiding, knew how to read the ancient language and translated the note for them: We have fi nished the release ahead of schedule again. All the tests pass, so we are taking the rest of the week off. We are going sailing. Since it s a team-building exercise, we hope we can get reimbursed for it. The explorers looked at each other in astonishment. Not only had they discovered the oldest software start-up in history, they had also discovered a team of programmers who, apparently, completed their code ahead of schedule on a regular basis. What was the secret of these ancient programmers? And what had happened to them? The expeditioners searched each cubicle for clues, and they found two well-worn booklets. One of them was called Learn To Sail In 30 Minutes, which explained the fate of the programmers. You are holding in your hands a translation of the other booklet, The Way of Testivus. Who wrote this mysterious booklet? What is Testivus? Only Google knows for sure. Is the content of this text responsible for these ancient programmers being able to complete projects ahead of schedule? We can t be sure, but we believe that the amazing prowess of these programmers was probably due to a combination of the Testivus philosophy, and the consumption of large amounts of the dark caffeinated liquid found in the cave. Read the booklet and draw your own conclusions. Alberto Savoia, CTO/Cofounder of Agitar Software April 2007, Mountain View, Calif.
4 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. If the code deserves to be written, it deserves to have tests.
5 Don t get stuck on unit testing dogma Dogma says: Do this. Do only this. Do it only this way. And do it because I tell you. Dogma is infl exible. Testing needs fl exibility. Dogma kills creativity. Testing needs creativity. Embrace unit testing karma Karma says: Do good things and good things will happen to you. Do them the way you know. Do them the way you like. Karma is fl exible. Testing needs fl exibility. Karma thrives on creativity. Testing needs creativity.
6 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. The test is more important than the unit The pupil asked the great master programmer Flying Feathers: What makes a test a unit test? This great master programmer answered: If it talks to the database, it is not a unit test. If it communicates across the network, it is not a unit test. If it touches the fi le system, it is not a unit test. If it can t run at the same time as any other unit tests, it is not a unit test. If you have to do special things to your environment to run it, it is not a unit test. Other master programmers jumped in and started arguing. Sorry I asked, said the pupil. Later that night, he received a note from the grand master programmer. The note said: The answer from the great master Flying Feathers is an excellent guide. Follow it, and most of the time you will do well. But don t get stuck on any dogma. Write the test that needs to be written. The pupil slept well. The other masters continued to argue long into the night.
7 The best time to test is when the code is fresh Your code is like clay. When it s fresh, it s soft and malleable. As it ages, it becomes hard and brittle. If you write tests when the code is fresh and easy to change, testing will be easy, and both the code and the tests will be strong. Tests not run waste away Run your tests often. Don t let them get stale. Rejoice when they pass. Rejoice when they fail. An imperfect test today is better than a perfect test someday The perfect is the enemy of the good. Don t wait for best to do better. Don t wait for better to do good. Write the test you can today.
8 An ugly test is better than no test When the code is ugly, the tests may be ugly. You don t like to write ugly tests, but ugly code needs testing the most. Don t let ugly code stop you from writing tests, but let ugly code stop you from writing more of it. Sometimes, the test justifies the means The pupil asked two master programmers: I cannot test this code without mocking and violating encapsulation. What should I do? One master programmer answered: Mocking is bad, and you should never violate encapsulation. Rewrite the code so you can test it properly. The other master programmer answered: Mocking is good and testing trumps encapsulation. The pupil, confused, went out for a beer. At the local watering hole he saw the great grand master programmer drinking beer and eating buffalo wings. Great grand master, said the pupil, I thought you did not drink. And aren t you a vegetarian? The great grand master smiled and replied: Sometimes your thirst is best quenched by beer and your hunger by buffalo wings. The pupil was no longer confused.
9 Only fools use no tools The farmer who does not use a plow is not a good farmer. The accountant who does not use an abacus is not a good accountant. Some tasks are best done with bare hands. Other tasks are best done with tools. It is not noble to do by hand what can be done better with a tool. It is not wise to use your head when your head is not needed. Good tests fail The pupil went to the master programmer and said: All my tests pass all the time. Don t I deserve a raise? The master slapped the pupil and replied: If all your tests pass, all the time, you need to write better tests. With a red cheek, the pupil went to HR to complain. But that s another story.
10 The Way of Testivus If you write code, write tests. Don t get stuck on unit testing dogma. Embrace unit testing karma. Think of code and test as one. The test is more important than the unit. The best time to test is when the code is fresh. Tests not run waste away. An imperfect test today is better than a perfect test someday. An ugly test is better than no test. Sometimes, the test justifi es the means. Only fools use no tools. Good tests fail.
12 This translation and printing of The Way of Testivus is brought to you by: JUnit Factory If you like the philosophy of Testivus, and believe in less unit testing dogma and more unit testing karma, please visit: JUnit Factory helps you increase your unit testing karma by amplifying and automating your testing efforts. Best of all, it s free.
Testing for Prostate Cancer Should I be tested? Is it the right choice for me? Prostate cancer affects many men. There are tests to find it early. There may be benefits and risks with testing. Research
How to Study Mathematics Written by Paul Dawkins Before I get into the tips for how to study math let me first say that everyone studies differently and there is no one right way to study for a math class.
the focused creator Learn the art of follow through & Achieve your goals by jake jorgovan This report is free and does not contain any affiliate links. Share it with the world under the terms of Creative
A Student Handbook for Choosing and Using Assistive Technology by Gayl Bowser OREGON TECHNOLOGY ACCESS PROGRAM OTAP Penny Reed WISCONSIN ASSISTIVE TECHNOLOGY INITIATIVE WATI Hey! Can I Try That? (Bowser
Why don t they just leave? (The Booklet) Written by Brian Fox - 1 - Forward Pioneering a Different Future During the past five years I have come to learn more about domestic violence and abuse than I ever
Read a Story That Will Change Your Life! The One Minute Manager is an easily read story which quickly shows you three very practical management techniques. As the story unfolds, you will discover several
Protect Your Family TB and Friends from TUBERCULOSIS The TB Contact Investigation What s Inside: Read this brochure today to learn how to protect your family and friends from TB. Then share it with people
MIGRAINE ADVICE FOR 7 TO 12 YEAR OLDS You are not alone seven out of every ten children in your school will probably have had a headache at some time What is your headache like? If you are reading this
I WANT TO START MY OWN USE-IT! WHAT IS USE-IT? WHAT IS USE-IT? USE-IT is the quality label for no-nonsense tourist info for young people. USE-IT initiatives currently exist in 40 cities in Europe. They
If you understand something in only one way, then you don't really understand it at all. The secret of what anything means to us depends on how we've connected it to all other things we know. Well-connected
MOST DIFFICULT INTERVIEW QUESTIONS When preparing for an interview, go through the following list of questions and write down appropriate responses. Don t memorize your answers; review them for content
How to be a Programmer: A Short, Comprehensive, and Personal Summary by Robert L. Read How to be a Programmer: A Short, Comprehensive, and Personal Summary by Robert L. Read Published 2002 Copyright 2002,
Ready for success in study, work and life Information for candidates For exams from 2015 First Certificate in English (FCE) www.cambridgeenglish.org/first How to use this guide You can print this document
Look after your mental health It s important to take care of yourself and get the most from life. This booklet suggests 10 practical ways to look after your mental health. What is mental health? Hi, how
On System Design Jim Waldo On System Design Jim Waldo Perspectives 2006-6 In an Essay Series Published by Sun Labs December 2006 This work first appeared as part of the OOPSLA 2006 Essays track, October
p T w o T h a n k s g i v i n g D a y G e n t l e m e n THERE IS ONE DAY THAT IS OURS. THERE IS ONE day when all Americans go back to the old home and eat a big dinner. Bless the day. The President gives
0 Table of Contents I. Introduction p. 2 II. Teacher Script p. 3 1. The Barter System p. 3 2. Foreign Currency p. 5 3. Counterfeit Money p. 5 4. Budgeting p. 6 III. Student Play: The World of Barter p.
PARTNERING WITH YOUR DOCTOR: A Guide for Persons with Memory Problems and Their Care Partners Alzheimer s Association Table of Contents PARTNERING WITH YOUR DOCTOR: When is Memory Loss a Problem? 2 What
How to survive your first year of graduate school in economics Matthew Pearson November 8, 2005 Dear First-year Graduate Student, Welcome to the threshold of hell (just kidding, more like the patio, or
Fire make your home safe Fire make your home safe Did you know? A smoke alarm could save you in a fire. 90 people die each year because their smoke alarm is not working. Most fires start when people are
A TEACHER S JOURNAL Amy R. Kari and Catherine B. Anderson Opportunities to Develop Place Value through Student Dialogue The problem 11 + 9 was written on the board at the front of the room. Eleven first
Composition as Explanation Gertrude Stein First delivered by the author as a lecture at Cambridge and Oxford, this essay was first published by the Hogarth Press in London in 1926 and revived in the volume
How Children Fail By John Holt, Penguin Education Foreword Most children in school fail. For a great many, this failure is avowed and absolute. Close to forty percent of those who begin high school, drop