Posts

Showing posts with the label clean code

What are Unit Tests and Why Should You Write Them?

Image
  Unit tests are simple scripts that check whether a given unit—class, function, module, etc. is working as expected.  They are meant to be simple, to cover the happy path of the code plus a few edge cases. They contribute to the long-term success of a project because of the reasons I discuss below.  As your code grows in size and complexity, tests will force you to break it into manageable pieces. Tests will become an additional resource for the next person working the code to figure out what it’s doing. As a junior programmer, you might be confused by unit tests. To make things worse, tests used as examples often make their purpose more unclear. When you see stuff like you are right to doubt whether there is a solid reason to spend any time writing them. Below, I show my reasons for writing unit tests. # What are unit tests? Unit tests are simple scripts that check whether a given unit—class, function, module, etc.—is working as expected. They are meant to be rather sim...