I have a big function that does several things, including some database operations, and calling another smaller function. Something like:
BigFunction()
{
DB.SomeTable.AddRow(newRow);
SmallFunction();
DB.OtherTable.AddRow(otherRow);
}
SmallFunction();
{
DB.SmallTable.AddRow(smallRow);
}
SmallFunction is already covered by it's own automated tests.
Now I want to write some automated tests for BigFunction.
When writing the automated tests for BigFunction, should I test that:
BigFunction calls SmallFunction (using a mock), or
The thing that SmallFunction does, actually happened (in my example: that smallRow is now in SmallTable)?
Some of my team says 1, because SmallFunction already has it's own tests, and so 2 is duplicating an existing test. If the purpose/result of SmallFunction changes, both tests will need to be changed.
Some say 2, because a) you should only mock when necessary, and b) you should test the result, not the implementation. If the implementation changes (BigFunction uses something other than SmallFunction to do what it needs, E.g.: BigFunction adds the smallRow itself, in this example), that will break the test, despite the code working fine.