3 ms·
Anecdote time: I worked on a project with a senior dev who was really into unit testing and only unit testing. The software had to be fully tested as tiny littl
by perrygeo 2mo ago
Anecdote time: I worked on a project with a senior dev who was really into unit testing and only unit testing. The software had to be fully tested as tiny little lego bricks with mocks galore. Because "if all the pieces were correct, the combination had to be correct" - his words. (I guess he'd never considered emergent behavior)
I'll never forget the cycle, after staunch objections to integration/e2e/manual tests and zealously insisting on full unit test coverage, the senior dev deployed changes ... boom. The process failed hard minutes after start because there was a bug in main. Full production outage. A bug so obvious we should have caught it by eye. Clearly, in the weeks developing the feature, he had never bothered to even run the application. Each part was fully polished in isolation but utterly failed when integrated into an application.
The way I've come to think of it: Unit tests are for libraries, a closed world where you can neatly define all inputs and outputs. Integration/E2E tests are for applications, an open world which require systems thinking, simulations not proofs. Know which world you're working in!
- LoganDark 2mo agoBoth is good.
- ad_fontes 2mo agoThat doesn't really sound like an indictment of unit tests. I don't really understand why someone would meticulously write a bunch of unit tests and then wait to prove them on a production deploy? Unit and integration tests serve different purposes and one isn't necessarily better than the other.
- simonw 2mo agoIt's an indictment of writing only unit tests. If the system also had integration tests this would likely have been caught, but even more important is the lesson that no amount of automated tests is an excuse not to actually try using your software yourself.
- perrygeo 2mo ago> Unit and integration tests serve different purposes and one isn't necessarily better than the other. If they serve different purposes, then one is by definition better than the other, given the circumstances. There's a whole class of applications containing very little pure logic; dumb pipes hooking together a database and client over a network. It's a categorical mistake to fully unit test these. There are only a few "units" to test; everything else is a side-effect (disk, network, etc). Yeah you can mock. My point is that mocks do not cover real world behavior, so those types of apps require an integration/e2e heavy set of tests. Conversely, if you've got a logic-heavy library, you need unit tests. You can't rely on the behavior as filtered through the application. Different purposes. But depending on what world you're working in, one is definitely better than the other.