Test-driven development 3 of 133
Random Thoughts
Another mental picture—programming is like exploring a dark house. You go from
room to room to room. Writing the test is like turning on the light. Then you can avoid
the furniture and save your shins (the clean design resulting from refactoring). Then
you’re ready to explore the next room.
I need an adjective which means “can be made to work in one step”. Atomic?
Achievable? Progressive?
At the different stages of the cycle you are solving different problems, so the
aesthetics change: Write a test-what should the API be? Make it compile—do as little
as possible to satisfy the compiler. Make it run—get back to green so you have
confidence. Refactor—remove duplication to prepare for the next test.
Interesting error. I had two tests, one USD->USD and one USD->GBP. If I had kept
the two assertions in the same test I wouldn’t have gone off the rails. What’s the rule
there? When do you add assertions to existing tests and when do you write a new test?
Splitting into orthogonal dimensions didn’t happen in either example. What up with
that? I thought that was such an important technique. Maybe that’s what “isolate
change” is really about, and taking smaller steps than I usually do results in making
progress along one dimension before having to make progress in the other.
More orientation material at the beginning of the example chapters—UML, lists of
tests running, to do list
Brian Marick on test-first tests as tests?
TDD as a gesture—technical, political, aesthetic, emotional. Relationship to other
practices.
Since people are likely to read the chapters in the example one or two at a time, it is
important to provide context at the beginning of each one-UML, maybe a list of the
test cases that are running at the beginning.
Test coverage. Use data structures that make special cases go away- iterators, number-
like numbers.
Balancing reasoning and testing. Every one of those reasoning steps is subject to error,
which adds risks. Replacing each and every reasoning step with a concrete test is
extremely expensive (impossibly expensive, really). There is some tradeoff. Maybe
that’s part of being a TDD—being aware of tradeoffs and intelligently choosing the
crossover point for this particular situation.
Assuming a certain geekoid value system—you want to do well by doing good (or
vice versa). That is, you like clean code, you enjoy the feeling of designing and
building well, and you want to be seen to be successful by managers and customers.
Code aesthetics. For any given set of test cases, we are trying to minimize a
complicated cost function—number of classes, number of methods, number of unique
selectors, number of arguments, complexity of flow of control, visibility of methods