📎 Webclip
No excuses, write unit tests
The text argues that unit testing is worth the upfront time because it exposes how functions behave, makes API changes visible, and catches bugs before they reach production. It also says that writing tests often leads to clearer, smaller, easier-to-test code.
Fichamento #
- Unit testing is presented as a useful practice even when teams worry about time, coverage disagreements, or broken tests.
- A unit can be any isolated block of code, including a function, though groups of functions are harder to test because they have more moving parts.
- Functions that always return the same output for the same inputs are easier to test because expectations can be set from their return values.
- Simple tests for
addandminusare used to show that even basic functions can be checked with expected outputs. - Testing simple functions can reveal how hard they are to use, what risks they carry in real use, and whether they do too much.
- The text says unit testing takes extra time upfront, but broken tests can be fixed earlier than bugs in production.
- If an API changes, tests should break; if they do not, code may reach production with other broken uses.
- Writing tests can improve code clarity because developers start thinking about testability while writing the code.
- The recommended flow is to make the code work, then write a test, then refactor.
- Broken tests are treated as useful because they force developers to understand inputs, outputs, and the impact of API changes.
- The author says there is no good reason to avoid at least some unit testing and recommends starting small and expanding from there.