3 ms·
>Why does everyone rethink a working strategy. Write lots of unit tests that are fast. * Because I want to avoid writing more code than necessary. * Because I
by crdoconnor 9y ago
>Why does everyone rethink a working strategy. Write lots of unit tests that are fast.
* Because I want to avoid writing more code than necessary.
* Because I want to avoid writing tightly coupled code.
* Because I'd rather have a test that takes 2x longer and catches 5% more bugs. Premature optimization and all that.
- chewbacha 9y agoI would recomnend not optimizing for less code. Optimize for reading less code. Unit tests actually tend to favor highly uncoupled code while integration seem to favor more coupling with e2e favoring the most coupling. I believe this is because the higher the level of testing the fewer public interfaces are thought about at lower levels. As for percentages about speed and coverage, that seems like a bad trade off of 5% gain for 100% slow down. Especially because test time compounds.
- crdoconnor 9y ago>I would recomnend not optimizing for less code. That is a terrible recommendation. Unless writing less code comes at the expense of readability or coupling you should always aim to write less code instead of more. >Unit tests actually tend to favor highly uncoupled code while integration seem to favor more coupling with e2e favoring the most coupling. It's the exact opposite. End to end tests do not even necessarily couple to a language, let alone specific modules. They can be used to refactor virtually the entire code base without rewriting any test code. That isn't to say that you should only use E2E tests. IMHO wherever there is a naturally loose coupling and a clean, relatively unchanging interface - that is a good place to cover with integration tests. The worst thing to surround with tests is a module whose API you know you will be changing (which will break the test when you do). >As for percentages about speed and coverage, that seems like a bad trade off of 5% gain for 100% slow down. Especially because test time compounds. No, it's an excellent trade off. CPU time is dirt cheap and bugs are very expensive. Moreover, you can run regression test suites while you eat, sleep and visit the water cooler so the absolute time does not really matter provided it catches bugs before release.
- jononor 9y agoLots of unit testing can cause tightly coupled code, if the units are too small and/or against internal APIs: The tests are tightly coupled to a piece of code which should have been able to change freely.
- throwaway5752 9y agoI don't know what to say... you have to write good code and good unit tests. I think talking how to do that is a bit outside of the scope here, but mocks for external apis & sensible function complexity metrics are good things.