In general, the order of implementing tests is important. When I pick the next test to implement, I find a test that will teach me something and which I have confidence I can make work.
Reminder: step size varies with confidence - when things are clear, we set a faster pace.
Note that this isn't the only possible strategy; the "Transformation Priority Premise" proposes that we want to always make the change that is "closest" to where we are now -- with "closest" being determined by a sort of weighted priority function.
What Beck wants to do is implement tearDown. But it is difficult to test - exception is a bit overloaded here. So instead of pursuing the difficult implementation, he introduces an intermediary -- separating what is complicated from what is difficult.
Here, that takes the form of a data structure to keep track of what is going on within the framework; to begin, just tracking tests run and tests failed.
What caught my eye here: having introduced a trivial fake implementation, he's immediately willing to "remove duplication" in counting the number of tests run - introducing an initialized value, incrementing the value, and so on.
But he does not choose to do the analogous refactoring on the test failed count, instead sticking with the hard coded value. "The tests don't demand it." I'm suspicious of that justification, in so far as with a single test, they didn't demand changing the test count either.
You might be able to make an argument from the idea that we started with an implicit counter for tests running, but there is no implicit counter for failures (because this test doesn't include the failing test code path) and therefore it's appropriate to make the former counter explicit, but not yet for the latter counter.
On the other hand, you probably can justify it via "make the next change easy".
Another point to note: in this first test, TestResult is not isolated from TestCase -- TestResult::testStarted is invoked by TestCase, not by the test. Beck is including within his observation the behavior of TestResult and also the protocol shared between TestResult and TestCase.
No comments:
Post a Comment