Hi guys,
I'm really getting to TDD recently, and after reading Kent Beck's book on Test Driven Development, I've still got many questions around test design in my mind.
One of the issues I'm currently having is the use of Mock objects. Take below a very simple that generates a report:
public string MakeFinancialReport()
{
return sys1.GetData() + sys2.GetData() + sys3.GetData();
}
The report must contain a header, a body, and a footer. So a quick test to see if those titles exist in the report:
public void TestReport()
{
string report = MakeFinancialReport();
Assert.IsTrue(report.Contains("[Title]") && report.Contains("[Body]") && report.Contains("[Footer]"));
}
To isolate the method, I guess I would be mocking away the sys1, sys2 and sys3 calls. Now, if they are all mocks, what have I got left to test? Also, when I do mock them, why must I have tell the mock objects that they are going to be expected to be called once and return X etc. Should it not just be a black box test and the MakeFinancialReport can make as many calls as it wants to build the report?
I'm getting confused with such a little problem, I'm not sure what I'm missing. I see Mocking as taking away testable code, and for most simple methods, what is left to test isn't helpful at all.