Over 13 installments, we've learned the technical side of TDD. You now have the
skills
to write tests and implement features on your own.
Things feel different at work than they do at school or on a personal project.
โWe're already swamped. When are we supposed to write tests?โ
โWon't writing tests double the schedule?โ
These are the kinds of questions you'll face. Today we'll talk candidly about the
costs
and
trade-offs
of applying TDD at work.
The Cost of Writing Tests and Its Effect on Productivity ๐
A common assumption is that TDD makes development take longer.
It does take longer at first, but it can save time over the life of the project.
It's much faster to start coding without tests. You can just type out an implementation. TDD feels slower because you spend time on both design and tests.
Maintenance
As features accumulate and the code gets more complex, the situation reverses. Changing code without tests can introduce bugs that take nights to fix. With TDD, you have a
safety net
that lets you make changes faster and with more confidence.
TDD is an investment in your future self. An hour spent today can save ten hours of overtime later.
At work, it's often impractical to test every line of code.
Pick the areas that need your attention most.
Which code should you always test, and which can you skip?
Core code to test
Financial logic, such as payments, settlements, and discount calculations.
Complex business rules, such as checking business hours and determining customer tiers.
Code that changes frequently or would have serious consequences if it failed.
Straightforward code you can skip
Simple getters and setters.
Configuration the framework handles, such as basic bean registration.
Simple integrations with other systems. You don't need to test the external library itself.
Basic UI layout and styling.
If a piece of code worries you, test it. If it's so simple that you can hardly imagine it breaking, you can skip the test.
You may know the benefits of TDD while your teammates have yet to see them. A question I hear often is, โMy team doesn't write tests. Is it okay if I start on my own?โ