DI is the biggest snake oil out there. The vast majority of time it's just used as a hack job to enable test isolation in weak languages and gives you no real-world decoupling.
Sure it's sometimes necessary, but I wish people would stop with the expostfacto justification. It doesn't make your code better if you add it just to test your code.
> DI is the biggest snake oil out there. The vast majority of time it's just used as a hack job to enable test isolation in weak languages and gives you no real-world decoupling.
Have you got any data or writings to back this up? I ask because what you write is my gut feeling but I can't put it into words or convince anyone.
That I have ended up programming in an area where the answer to testing is "spin that into its own class so it's testable" when the code is used in a single place, would be fine as a private or protected method, but still needs tests to confirm the output is right, drives me crazy. For libraries sure, but for checking the date parsing is right, that you didn't mess up the calculation... just let me test the damn protected method and be done with it.
Hundreds of tiny classes benefits no one, only the testing framework.
I agree with this. FWIW, Java (for instance) could treat testing as a privileged mode of execution, allowing for all properties (even private ones) to be get/set/interacted with as if they were public, for the duration of the test. This would simplify so many things and get rid of so much boilerplate code.
I agree actually and was thinking that visibility modifiers should not really deny access for the internals of the class under testing. Maybe c++’s friend classes would be a good solution?
Or I don’t really find groovy to be the best thing, but it could probably be hacked to translate private accesses to reflection calls under the hood making testedClass.privateField actually callable?
Allow all properties and methods to be get/set/called freely by the test harness (such as JUnit in Java's case), as if they were public all along. The need for DI in testing would be greatly reduced, while keeping the public/private distinction intact while the code is running as normal.
Sure it's sometimes necessary, but I wish people would stop with the expostfacto justification. It doesn't make your code better if you add it just to test your code.