Each class must have unit tests. Every class’s unit tests must score 100%. On C3, we use Kent Beck’s public domain testing framework, augmented with a GUI that runs all the tests and shows the percent correct. At this writing, there are over 1300 unit tests, and they all run at 100 percent.

We recommend that unit tests be written before the class is written. This is a good way to focus attention on what the class is really about. In any case, a class isn’t done until its unit tests are in the test suite.

When classes are released, all unit tests must be running at 100 percent. All. That is, if the changes you make break the unit tests for some other class, the problem must be resolved before you release.

On the contrary, what if I’m not the one who broke the test, or what if someone is using my class incorrectly?

  • Since the unit tests ran at 100 percent before you released, you did break the tests.
  • If someone is using your class incorrectly, why did the tests run at 100 percent when they released? Something you changed has caused the problem, because you know the tests ran at 100% before you started to release your code.
  • Even if the class is used incorrectly, you need to resolve the problem before you release. Partner with the user of your class if need be.

To emphasize the point: all the unit tests must run at 100 percent, all the time.