I have a nontrivial service object designed with TDD. It started with a simple task: for an object from a queue, create an attempt for asynchronous processing. So I wrote a test around my constructAttempt() method:
void constructAttempt() {...}
There are many possible scenarios to consider, so I have a dozen tests for this method.
Then I applied what I really needed: scan the entire queue and build a batch of attempts. So the code looks more:
public void go() { for (QueuedItem item : getQueuedItems()) { constructAttempt(item); } }
So, I added a new test or two for this go() method.
Finally, I found that I need preprocessing, which can sometimes affect constructAttempt() . Now the code looks more:
public void go() { preprocess(); for (QueuedItem item : getQueuedItems()) { constructAttempt(item); } }
I have a few doubts as to what I should do now.
Should I keep the code as is, with constructAttempt() , preprocess() and go() tested independently? Why yes / why not? I risk not covering the side effects of pre-processing and interruption of encapsulation.
Or should I reorganize my entire test suite to only call go() (which is the only public method)? Why yes / why not? This would make the tests a little more obscure, but on the other hand, it would take into account all possible interactions. In fact, this will become a black-field test using only the public API, which may not correspond to TDD.
language-agnostic tdd testing
Konrad garus
source share