I’ve been spending a fair amount of time recently writing GUI rendering code. I’ve also been spending a fair amount of time recently grappling with unfamiliar API’s. These experiences have revealed two areas where test-first development doesn’t quite work:
- GUI rendering code where “correctness” is determined by how something must look
- Early stage implementation where interface churn is the norm
The first case encompasses virtually all of GUI development, regardless of whether your GUI is an HTML page or a traditional Windows application. In these cases, whether or not something is “correct” depends on how an object appears. Unfortunately, there are usually several different ways to render the object, all of which yield correct results. Furthermore, it’s really hard to determine how an object is rendered programmatically, whereas it is usually quite simple for a human to determine if an object looks “correct”.
Dan Dunham recently wrote about this problem. One suggestion that makes a lot of sense involves validating the objects that define the state for the to-be-rendered object (e.g. 10x20 pixel green box at 5,20). This way your unit tests can test to see whether the object contains the expected state at the expected time.
The second case commonly turns up when you have finished writing your disposable prototypes, and have begun writing your production code. In these early stages of development, your class interfaces tend to change very quickly. The desired interaction between different classes and objects in your system is generally never evident from the beginning, and your are forced to discard initial designs as your code quickly evolves.
I found that maintaining a suite of unit tests for these classes greatly increases the amount of friction involved in changing a class. This causes me to rapidly run into my 7+/-2 limitations, and slows down the development process in these critical early stages of development. This experience has led me to change my approach in these cases: I build my unit tests once the interactions between different classes and objects have been established.
1 archived reader comment
Phlip (2004-01-14)
The book /Test First User Interfaces/ is going to cover these issues in great detail.
;-)