Warming Up to Unit Testing
When you first hear about unit tests it seems like the greatest idea ever. Automation of a process you already do manually makes that process repeated-able and quick. When I was a junior programmer I was all over it.<p>Over the years I have come to reject some things that are seemingly fundamental to software engineering in the industry. One of them is unit testing. I don&#x27;t believe that unit testing is harmful in itself, but excessive use of it is a sign of weakness in another area.<p>- if your code relies on unit testing for correctness than your coding methodology (or language) is error prone. A good programming methodology where the domain is well understood usually does not need a single unit test.<p>- If your code base utilizes dependency injection to make the code more &quot;testable&quot; with mocks, you are making the code 10x worse. There are other ways to make your code more modular without injecting new scope, logic and apis into an object.<p>This logic sort of applies integration tests which is basically testing the same thing as unit tests but touching functions that have IO. However it is a little different. If your program does Not need unit tests but needs integration tests it means things like:<p>- your type checker does not extend across systems<p>- the programming methodologies become more error prone as you move to other systems and you have no control over it.<p>- you lack understanding of the foreign system.<p>The thing with integration tests is that all of the above is largely inevitable and integration testing really becomes the only way to correlate (not verify) the entire system with correctness when you lack the integrated approach of a single programming language. Therefore because of this I am not against integration testing.<p>I recently green fielded a small micro-service at my company and I did not write a single unit test. It had one logic error and that was largely due to a flaw in the type checker. I can imagine many engineers being aghast at the whole concept.<p>So essentially I&#x27;ve had the opposite conclusion. Unit testing to me is a symptom of bad engineering practices. If you rely on it, something is wrong.