Write tests. Not too many. Mostly integration
I go the complete opposite way.<p>I&#x27;ve tried various testing strategies over 15~ different companies in all sorts of environments, and unit tests are the only thing that really work (IF you can convince the team to do it...and that&#x27;s a big IF).<p>The article starts with a point I agree with: the lower in the pyramid, the cheaper the tests but the lower the confidence level they bring. That&#x27;s true.<p>Where I disagree is how much the difference on confidence and cost are.<p>I can bang out 500 unit tests faster than I can do just a few E2E tests in most large apps. They require almost no trial and error, no real engineering (I feel strongly that abstraction in unit tests is bad), and all around are so easy to write, I don&#x27;t mind if I have to toss out 150 of time when I make a significant refactor.<p>E2E tests are amazingly brittle and require a careful understanding of the whole system. They&#x27;re impossibly expensive to write. They&#x27;re the only thing that tells you that stuff works though. So you want at least a few of these.<p>Integration tests are just flat out awkward: you need understanding of a significant portion of code you did not write or touch, they often require complex fixtures (because your test will go through several code paths and might depend on a lot of arguments), they&#x27;re slower (because a lot of code run), and while you don&#x27;t throw them away when changing implementation details (unless they involve side effects), you still throw them away when refactoring or changing public interfaces. I&#x27;ve worked with a lot of people who were very vocal about these being so much better, then in the same breath complain that they spent all day writing integration tests.<p>There&#x27;s an exception here which is acceptance tests for libraries, especially when doing a full rewrite: the tests that tell you public interfaces used outside of the current context work (as opposed to public interface of objects used in the implementation). Eg: if I was to test lodash or react, that&#x27;s how I&#x27;d do it.<p>Unit tests to be are about a lot more than &quot;is this change breaking my code&quot;. And if that&#x27;s all you care about, you&#x27;re missing a big part of the point.<p>If you have 3 units, A, B and C. A calls B which calls C. If you have a test for A in the context of B, a text for B in the context of C, and a test for C, and they all pass, you know that A + B + C will work. But when writing the tests, you only had to care about itty bitty tiny pieces of code, which made things super cheap.<p>Then you get other huge benefit: the quality of the entire code base is higher (a side effect of it having testable interfaces all across), the reasoning behind each piece of code is explicit (no one wrote a function that work and they &#x27;re not sure why, else the test would be very hard to write), you automatically have a document representing &quot;intentions&quot;.<p>And yes, if you change a module, even if its not expose to your customers, the public interface of that module has tests and the tests will break. But they usually take nothing but a few minutes (often a few seconds) to write. They&#x27;re cheap enough to be disposable.<p>And once you have 80%ish unit test coverage, you actually have a very high confidence level. I&#x27;ve gone through major refactoring of multi-million line of code apps with almost no bugs on pure unit tests. You&#x27;t think the 20% of untested code would be a source of bug, but statistically, that&#x27;s just not how it happens.<p>In term of person-hour to ROI, pure unit tests just straight up win out.<p>The reason software engineers fight back to hard against them is that they&#x27;re brain dead and repetitive to write, and  they can&#x27;t resist overengineering. &quot;This is such a simple test for such a simple piece of code, why should I test it?!&quot;. That&#x27;s the point. All unit tests should be like this.