Re:Ask HN: I am busy with too many things at once
by devdas on Friday July 03, 2015 @09:28AM
(#9825439)
If you have a function which invokes a different object (or more commonly, a different network service), you pass that as a parameter instead of making a call inside the function.
It makes replacing service with fake_service_object easier, thus simplifying the test process.
Common use case:
If your service was a remote database, you can replace the database handle with a mock object which pretends to be a DB but is actually a simple object returning hardcoded values.
foo() { service = someRemoteService(authn, authz); http://lookingglass.internal.adm.bol.com/?page=TAM+Middlewar... }
is replaced by
foo(service) { do_something_with_service(service) }
It makes replacing service with fake_service_object easier, thus simplifying the test process.
Common use case: If your service was a remote database, you can replace the database handle with a mock object which pretends to be a DB but is actually a simple object returning hardcoded values.