next up previous
Next: Write The Tests First Up: Unit Testing in Java Previous: Tests Should Check Themselves

Tests Should be an Integral Part of the Coding Process

When we write tests, we should keep in mind that the tests we write are a very powerful form of documentation. When another programmer reads our tests, he can quickly learn how to invoke our code, and how it will behave What's more, he can verify that our code meets this documentation by running the tests (compare this with English comments). For this reason, we should be careful to develop small and relatively simple tests that are easily readable by others.

Additionally, these tests should capture the most interesting places where the code may break. Determining where these places are is best done when the code is actually written. For this reason, it's a good practice to alternate writing tests and writing code in small steps, checking at each step that all tests still pass. Not only will this help you to write penetrating tests while the code is fresh in your mind, but it will also help you to discover bugs much more quickly and easily, as you will know when a test fails that only a very small block of code could be the culprit.


next up previous
Next: Write The Tests First Up: Unit Testing in Java Previous: Tests Should Check Themselves
Corky Cartwright 2004-02-05