I have not read widely or completely about TDD, but I feel that I know the basics.
One point of TDD is that you write tests first. In the case of a calculator program, perhaps one test case looks like this:
public class CalculatorTest { public void shouldSumOneAndOneCorrectly() { Calculator calc = new Calculator(); calc.push(new Number(1)); calc.push(new SumOperator()); calc.push(new Number(1)); Number sum = calc.equals(); assert(sum.equals(new Number(2))); } }
If I write the above test before writing any implementation, then I am faced with this problem: am I testing if the class of the calculator is summed correctly, or should I check the correctness of the sum of the Number class? Of course, this assumes that the Calculator class will call the number.add (number) function in its implementation somewhere. But I thought you shouldn't think about implementation when writing your tests first?
If I start writing tests for the calculator class, and then during implementation, they will understand that my Calculator class simply delegates and coordinates folded objects, then I write tests for those composite objects? Hold the calculator tests?
You start writing tests at a very high level (Calculator), and then when you implement the functionality and create grouped classes, write more tests for these classes?
Hope I make sense.
source share