This is my doubt on what we regard as a “unit” while unit-testing.
say I have a method like this,
public String myBigMethod()
{
String resultOne = moduleOneObject.someOperation();
String resultTwo = moduleTwoObject.someOtherOperation(resultOne);
return resultTwo;
}
( I have unit-tests written for someOperation() and someOtherOperation() seperately )
and this myBigMethod() kinda integrates ModuleOne and ModuleTwo by using them as above,
then, is the method “myBigMethod()” still considered as a “unit” ?
Should I be writing a test for this “myBigMethod()” ?
Say I have written a test for myBigMethod()… If testSomeOperation() fails, it would also result in testMyBigMethod() to fail… Now testMyBigMethod()’s failure might show a not-so-correct-location of the bug.
One-Cause causing two tests to fail doesn’t look so good to me. But donno if there’s any better way…? Is there ?
Thanks !
The test for
myBigMethod()should test the combination of the results of the other two methods called. So, yes it should fail if either of the methods it depends on fails, but it should be testing more. There should be some case wheresomeOperation()andsomeOtherOperation()work correctly, butmyBigMethod()can still fail. If that’s not possible, then there’s no need to testmyBigMethod().