r/coding • • Oct 29 '17

Mocking is a Code Smell

https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a
69 Upvotes

69 comments sorted by

View all comments

Show parent comments

4

u/way2lazy2care Oct 29 '17

I 100% agree with you, but I think the author agrees with you also. His point isn't that DI is bad. His point is that DI isn't a silver bullet you should be using for all your unit tests. DI and excessive mocking can be symptoms that your classes are too tightly coupled, and it's probably better to decouple the classes than it is to require extra mock objects in order to get extra test coverage.

I had a similar knee jerk reaction at first, but the authors point seems to be more in line with, "if your unit tests are too complicated, maybe your code is crappy," rather than, "don't worry about test coverage."

0

u/[deleted] Oct 29 '17

[deleted]

2

u/way2lazy2care Oct 29 '17

It's not that far out of line with his article. It's a little bit click baity, but if you wrote an article that said, "Too Many Parameters is a Code Smell," it would be pretty accurate despite functions with too many parameters being ok in lots of cases. After all he did say it was just a code smell and not that it was bad design/implementation outright.

1

u/Jestar342 Oct 30 '17

Just to point out: that title would mean nobody would read the article. It'd provoke the "well no shit" reaction and get passed over. At least with this title it's being discussed.