Tuesday, December 23, 2008

How We Used to Do Unit Testing

Reader Charles sends a question I've frequently had when consulting with testing organizations who are weary of having code thrown at them "over the wall."

Charles

From your experience in software, what are some good practices you have found for what is now known as "Unit Test?"

I have mine, I want to see if we have similar experiences.

I also have a motive, I get the opportunity to write our "Unit Test Procedure", so I want to capture "Good Practices" that developers can use.

Ack!--Unit Test Procedure!!! I wish we could have names like, "Menu of Good Unit Test Practices, Choose One or More that Make Sense for your Unit, or Use and Add a New Practice to the Menu of Good Practices (Include Provenance or Example)."

Jerry


Honor Unit Testing


1. Well, that's probably number one, the name and prestige you give to the process. If you belittle it, you will have poor results. If you reward it ... finish the sentence. I don't recall if we even had a name for it in the early days. It was just assumed that any pro would do a damn good job of this activity, not to be embarrassed by unit bugs found in integration test or system test--or god help us, in production.

Build Small and Simple

2. The next most important thing is to design to build in testable pieces. Small as possible, but no smaller. Cleanly structured, with no testing traps like hidden memory that might make the code not really reentrant.

Be Completely Open

3. Next is complete openness, getting as many eyes on it as you could get, but certainly not just one pair.

Test First

4. Today what we did is called Test Before Code, or perhaps Test Before Design. Ideally, we sketched out a set of test cases before putting pencil to coding pad. (We didn't have terminals or PCs in those early days.) These were punched into cards and put in the permanent test case library.

Take Advantage of Individual Skills and Help Each Other

5. After that, I recall things breaking down into tactics favored by each individual. Generally, we unit tested each other's code, and anyone having trouble could and did call on anyone else to help out.

Don't Green Dot

I think if people did these things today, we'd be in a lot less trouble. I know because there are people who do these things today, and they tend to stay out of trouble. On the other hand, people who just throw code at a compile and say "it's unit tested" as soon as they see a green dot, tend to be in trouble all the time.

Comments welcome!