The Artima Developer Community
Sponsored Link

Weblogs Forum
The Way of Testivus - Unit Testing Wisdom From An Ancient Software Start-up

20 replies on 2 pages. Most recent reply: May 21, 2007 4:09 PM by Alberto Savoia

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 20 replies on 2 pages [ 1 2 | » ]
Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

The Way of Testivus - Unit Testing Wisdom From An Ancient Software Start-up (View in Weblogs)
Posted: Apr 26, 2007 7:32 PM
Reply to this message Reply
Summary
Some good advice on developer and unit testing, packaged as cryptic bits of ancient Eastern wisdom in the hope of getting your attention.
Advertisement

Please note: for a nicely formatted, easy to read, and perfect for printing, copy of this material in PDF (complete with antique looking papyrus) you can go to:

http://www.agitar.com/downloads/TheWayOfTestivus.pdf

The Way of Testivus

Less unit testing dogma. More unit testing karma.

Translated by Alberto Savoia

Translator’s Introduction

In May 2006, an ill-prepared international expedition to the Himalayas lost its way. After two weeks of wondering around, hungry, thirsty, and smelling like inexperienced expeditioners who got lost for two weeks, they stumbled upon the entrance to an ancient cave.

Once inside, they saw a maze of ancient, and messy, 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 office they found barrels of dark liquid which they later identified as early examples of carbonated and highly caffeinated drink and a ping-pong table. They realized that the cave was an ancient software start-up. The oldest one on record. Older even than Netscape.

Among the many things they discovered inside the cave was 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 finished 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 found two mysterious 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, April 2007, Mountain View, Ca

The Way of Testivus

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.

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 inflexible. Testing needs flexibility.

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 flexible. Testing needs flexibility.

Karma thrives on creativity. Testing needs creativity.

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 file 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, hearing this conversation, jumped in with dissenting opinions and started to argue loudly.

“Sorry I asked”, said the pupil said the pupil as he left. Later that night, he received a note from the great grand master programmer:

“The answer from the great master Flying Feathers is an excellent guide. If you follow it 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.

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.

If you write the tests when the code is old and hard to change, testing will be hard and both the tests and the code will be brittle.

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.

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.

Only fools use no tools

The farmer who does not use a plow is not a good farmer.

The accountant that 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.

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 justifies the means.
  • Only fools use no tools.
  • Good tests fail.

I hope you enjoyed reading "The Way of Testivus". Let's finish what these ancient programmers started, feel free to send in your suggestions for more Testivus wisdom.


Doug Anderson

Posts: 5
Nickname: dougbangko
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: Apr 30, 2007 7:40 AM
Reply to this message Reply
Excellent.

I will add a link to it from my own Testing Concepts site.
http://www.thai-software.com/Testing/

Coder Coder

Posts: 1
Nickname: ddwyer
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Start-up Posted: Apr 30, 2007 12:22 PM
Reply to this message Reply
If an exception happens in code and is caught without report, did it make a sound?

Ammon Lauritzen

Posts: 1
Nickname: allaryin
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: Apr 30, 2007 7:21 PM
Reply to this message Reply
A wonderful article, and a good modern analogue to the venerable Tao of Programming.

I would, however, make one suggestion.

Please, lose the wacky formatting. Multiple pages of italics, variable spacing and alignment... make for a very difficult read.

disney

Posts: 35
Nickname: juggler
Registered: Jan, 2003

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 1, 2007 5:29 AM
Reply to this message Reply
Agreed! Great article; Very Bad formatting. You'll have lost at least 30% of your potential readers with a font that makes them work THAT hard.

Doug Anderson

Posts: 5
Nickname: dougbangko
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 1, 2007 5:40 AM
Reply to this message Reply
Jeez, guys, you don't get it. It's supposed to look like handwriting on an old parchment.

Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 1, 2007 10:10 AM
Reply to this message Reply
Thank you for the feedback on the formatting. As Doug mentioned, it was supposed to look like some ancient script. It looked fine on my browser, but I understand that different browsers did not render it as well.

In this case readability trumps aesthetics, so I re-formatted using standard fonts.

Alberto

Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 3, 2007 10:49 AM
Reply to this message Reply
> A wonderful article, and a good modern analogue to the
> venerable Tao of Programming.
>
> I would, however, make one suggestion.
>
> Please, lose the wacky formatting. Multiple pages of
> italics, variable spacing and alignment... make for a very
> difficult read.

Thank you for the honest feedback on the "wacky" formatting. I removed all "wacky" formatting from the post, but since the document looks, and reads, much better as I originally paged it, I put a PDF copy of it(complete with antique looking papyrus) on our website:

http://www.agitar.com/downloads/TheWayOfTestivus.pdf

Thanks,

Alberto

Doug Anderson

Posts: 5
Nickname: dougbangko
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 3, 2007 11:54 AM
Reply to this message Reply
Very well done

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 3, 2007 8:00 PM
Reply to this message Reply
What is Testivus' wisdom concerning the proper percentage of test coverage?

Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 4, 2007 10:34 AM
Reply to this message Reply
Hi Morgan,

Good question.

Tough question.

It took some serious thinking. To see what I came up with check out my latest blog (it's an often asked question, worthy of its own blog entry):

http://www.artima.com/forums/flat.jsp?forum=106&thread=204677

Philippe Antras

Posts: 2
Nickname: pantras
Registered: May, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 7, 2007 4:40 PM
Reply to this message Reply
Well put, Alberto.

Thanks for publishing this story full of wisdom. I liked it so much that I created a lil' poster with your ancient advices, see http://pantras.free.fr/articles/testivus.html

Rgds,
Philippe

Bill Burris

Posts: 24
Nickname: billburris
Registered: Aug, 2003

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 9, 2007 5:06 PM
Reply to this message Reply
Only fools use no tools

The question is where do I find tools that are usable?

Every once in a while I try to figure out how to use CppUnit, but it just doesn't make any sense. After banging my head on CppUnit for a couple of days, I just go back to digging my way through my code the old way. This code was started 10 years ago, and I didn't know anything about unit testing and TDD back then. 99% of my new code is written in C#.

I have been writing C/C++/C# code for 20 years, but CppUnit looks like it is written in a foreign language.

I could just poke away at it for days or weeks until it makes sense, but once I get past this bug that is bugging me, it might be 6 months, a year or more before I need to work with C++ again.

Nice stories about ancient programming teams, and how things should be done are interesting, but they are of no help when you can't get the basic tools to work.

Bill

Doug Anderson

Posts: 5
Nickname: dougbangko
Registered: Apr, 2007

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 9, 2007 7:10 PM
Reply to this message Reply
I have been programming for more than 40 years. I learned long ago that testing is much easier if debugging tools are programmed in when developing the code. When I write a subroutine, I ask myself, "What do I need to know to debug this code?" Then I add the debugging code right then and there. Depending on the language and the application, this debugging code might be on a conditional compile-time switch, or on a run-time switch. Adding debugging code to an existing program is painful, necessitating specialised tools for some languages, like C++ and C#. Putting debugging code in while writing is easy.

Alberto Savoia

Posts: 95
Nickname: agitator
Registered: Aug, 2004

Re: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Star Posted: May 15, 2007 11:02 AM
Reply to this message Reply
Hi Philippe,

I am glad you liked "The Way of Testivus" and thank you for the poster.

Would it be too much to ask for a French translation? :-) We already had some people translate various Testivus epigrams in Spanish.

Alberto

P.S. I have put a nicely formatted version on

http://www.agitar.com/downloads/TheWayOfTestivus.pdf

Flat View: This topic has 20 replies on 2 pages [ 1  2 | » ]
Topic: The Way of Testivus - Unit Testing Wisdom From An Ancient Software Start-up Previous Topic   Next Topic Topic: Java: a Success Story Beyond JavaOne 2007


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us