Suppose I have similar function:

Helper2 helper2;
public void myFunc(Helper helper)
    if (....)

In my unit test should I assert that my SecondFunc or ThirdFunc are called once (isn't this tighly coupling and hardcoding) or just mock/stub them to do dummy things and assert if the dummy things are done?

2 Answers 2


It depends on what you are testing.

For pure simple helper as you have here, I may not really bother about them in my test on higher end functions, and have unit test dedicated to the helper function. But if my helper rely on some external system, I would do some mock to check that the function I want to be called is properly called: If my helper is doing some database query for example, I'd check that the query function/method is properly called, and mock its result if I want to test for specific error.


Test the API.

  • If Helper has tests of its own, you mock it here
  • If Helper is an internal class to this API, don't let it leak (not even to tests).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.