Test-Driven Development (TDD) is one of the core practices of XP. Generally when I introduce people to the concept, I either get a look that says I’m crazy, or they comment on how they used to do that “back in the day”, which generally leads to discussions about walking uphill 20 miles in the snow to pick up some punch cards, etc, etc.
Lately I’ve been reviewing my wife’s materials from her I/O Psychology classes. One of the books that has really caught my interest is Understanding Motivation and Emotion by Johnmarshall Reeve. I’ve been reading a section on cognitive approaches to motivation, when I stumbled across the TOTE model.
Turns out that in 1960, a group of pyschologists (Miller, Galanter & Pribram) theorized that people have in their minds what is ideal in the current situation, and when they find a mismatch between the ideal state and the current one, they adopt a plan of action to correct it. They called it the Test-Operate-Test-Exit (TOTE) model, and it looks like this:
- Test – Compare present state with ideal state
- Operate – Act on environment to realize ideal state
- Test – Compare present state with ideal state. If congruous, goto 4, else goto 2
- Exit – Present state in congruity with ideal state
Which, oddly enough, looks very similar to the TDD model:
- Write a failing test which describes the ideal state you want the system to be in
- Modify the system to make the test pass
- Rerun the test to see if the modifications made the test pass. If yes, goto 4, else goto 2
So, the interesting thing is that TDD feels so natural to so many people because it is how they would normally act in a given situation.