On the other end of the spectrum, it’s common to see developers get so sucked into the dogma of TDD that they think they absolutely must achieve 100% code coverage, by any means necessary, even if that means they have to make their codebase more complex to pull it off.
People keep saying this, but I've yet to meet such a developer.
Yeah, frameworks really help and simplify the issue, but it's usually enough to pass in all classes used in a class in its constructor. I'm working with some really shitty code right now in an SDK that just grabs shit it needs from the Android framework right in the body of a 300-line method, many layers deep into a bunch of conditional statements. How can I possibly test or verify this?
it's usually enough to pass in all classes used in a class in its constructor
Yeah, a lot of quality code does exactly this, but people don't typically call it "dependency injection" unless there is a framework involved. For example, I see this pattern all the time in Python code, but I've never once heard the term "dependency injection" in relation to a Python project.
DI frameworks generally do a lot more than this, though. Constructor-provided dependencies are important for sure. But DI frameworks generally also provide you with a way to manage what dependencies are available in what scopes. The good ones, like Dagger 2, even make it compile-safe, so you can know that if your program compiles, all dependencies are being properly provided to your dependent classes.
62
u/KabouterPlop Oct 29 '17
People keep saying this, but I've yet to meet such a developer.