You should use polymorphism through interface or function argument and dependency injection. That means that thanks to interface or function argument you can change the effective implementation and dependency injection will allow you to change this implementation according your need. You can for example make your function f1 accept an interface declaring makeHttpRequest or a function and you change the implementation from an effective one to a mock when necessary. Have a nice day.