I'm fairly new to UnitTesting and just encountered a situation I don't know how to handle and I'd appreciate any hints :)
The situation is as follows, imagine two methods:
// simple standalone method public bool HelperMethod(string substr) { return substr.Equals("abc"); } // complex method making (multiple) use of HelperMethod public bool ActualMethod(string str) { for (var i=0; i<str.Length; i++) { var substr = str.Substring(i, 3); if (HelperMethod(substr)) return true; } return false; } HelperMethod functions without dependencies, ActualMethod however depends on HelperMethod and therefore its UnitTest will fail if HelperMethod's one does.
Actually, if I'm not mistaken, this is where mocking/dependency injection should come to rescue.
But in this specific case, I'd like to test several (arbitrary large) edge-cases (which may not be necessary for the code above, but the actual ActualMethod implementation is a part of fairly complex syntax parser). Since HelperMethod is called multiple times in each ActualMethod call, I would have to mock hundreds of HelperMethod calls for my test which just seems unbearable (now just imagine the number of needed HelperMethod calls would be quadratic to the input..).
My question is: how could one elegantly test a method that delegates a huge number of calls to another method? Should I really mock all these delegate calls? Or am I maybe allowed to make the method test depend on the other method's test (sth. like Assert(HelperMethodPassed)? Or is there no way around changing the design of the implementation?
Unfortunately inlining HelperMethod in the ActualMethod isn't possible because other methods rely on it as well.
Thanks in advance, I'd really appreciate any help! :)
PS: The project that is being tested is written in C# and I'm currently using the MSTest framework (but I'm open for switching to another framework if this solves the problematic).
Edit: explicitly marked HelperMethod and ActualMethod as public.