vendredi 7 octobre 2016

Dependency injection vs higher order function for testability?

I'm working with Python and Javascript. I was reading up on writing more testable code and came across the subject of dependency injection (A) and higher order functions (B). I'm gonna summarize how I understand these so others can point out if I'm not getting it:

A) Pass a module or class dependency through the parameters so that we can easily switch it with a mock when we want to test

B) Pass a function dependency through the parameters for the exact same reasons as (A)

Let's say here the dependency in question concerns getting data from a database. Is there any difference when it comes to code testability between the two approaches?

Aucun commentaire:

Enregistrer un commentaire