2 ms·
If you define unit tests as tests which test non-divisible units on a low level, then by definition they are a form of tight coupling. The most loosely coupled
by crdoconnor 9y ago
If you define unit tests as tests which test non-divisible units on a low level, then by definition they are a form of tight coupling.
The most loosely coupled form of test would be an end to end test (most loosely coupled, but obviously not without its disadvantages).
Since the pain of dealing with one form of tight coupling is magnified by having another form present, the presence of unit tests act as a sort of canary in the coalmine: if your unit tests are extra painful today, that's probably because the part they are connecting with has a high degree of tight coupling. That might (or might not) lead you to refactor and decouple the rest of the code base in an attempt to mute that pain. Either way you'll feel the pain.
I believe this effect is real. I also don't do this myself, because I don't believe in self flagellation as a means to enlightenment. The best thing to couple your tests to depends upon a range of factors, IMHO, and getting religious about where to couple anything is the worst thing you could do, especially if that religion dictates tight coupling (unit testing all the things).
Method length and complexity probably go up because if you focus on loose coupling (to mute the "unit testing pain") to the exclusion of other good code qualities - less code/less complex code - then those qualities will be sacrificed.