Unit Tests are Misunderstood

I have been re-reading Growing Object-Oriented Software Guided By Tests recently if you haven't read it I highly recommend it. In it, they explain the difference between internal quality and external quality and how the different types of tests relate to each one.

In the book, they explain...... Diagram




I always knew this, but it was difficult to explain, especially to people that weren't involved in actually coding. They would see the value manual tests and end-to-end tests, it ensured that the system did what it was supposed to do, but what about unit tests. Th


Optimize build speed

I think part of the problem of understanding unit tests, is that people don't understand what is the purpose of unit tests. I often hear things like we don't really need unit tests if we have end-to-end and integration tests, or why do we still have bugs if we have all these unit tests.


This means that both are needed, the external quality ones to make sure we are delivering what the customer wants, but also the unit tests that help us make the code structural sound. This problem is made worse by the fact that if external quality slips, we are immediately away, while internal quality can be ignored for a while without the outside world is aware.

So if it's not readily apparent if internal quality slips, is it really that important. It is when we need to make a change. Good unit tests steer us in a direction to make the code more cohesive and loosely coupled, and therefore easier to change. And that is the essence of TDD and unit testing, it allows us to easily change our code to adapt to changing requirements, new features, or just better designs.






Comments

Popular Posts