PromleeBlog

posting thumbnail
Applying TDD in Practice โ€” TDD with Spring Boot, Part 14

๐Ÿ“…

Before We Begin ๐Ÿ”—

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.

How Productivity Changes Over Time ๐Ÿ”—

TDD is an investment in your future self. An hour spent today can save ten hours of overtime later.

What Should You Test, and What Can You Skip? ๐Ÿ”—

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?

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.

Introducing TDD to a Team ๐Ÿ”—

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?โ€™

Start on Your Own ๐Ÿ”—

Start with your own work before trying to change the team's process.
  1. When you find a bug, first write a test that reproduces it.
  2. Fix the code and confirm the test passes.
  3. Deploy with confidence.
Over time, teammates may notice that your code has fewer bugs and that you seem comfortable changing it.

When they show interest, share your experience with TDD. That's how the practice can spread naturally. The strongest case you can make is to show the
results
.

Working with Legacy Code ๐Ÿ”—

Sometimes you'll inherit a large codebase that already exists and has no tests. Trying to cover the entire thing with tests is unrealistic.

The Boy Scout Rule ๐Ÿ”—

Leave the place cleaner than you found it.
Apply that rule to code by writing tests for
the area you need to change today
.

  1. Put a
    safety net of tests
    around the code you're about to change.
  2. Make the change and refactor.
  3. Commit your work.

Growing coverage bit by bit is a practical, safe way to handle legacy code.

Conclusion ๐Ÿ”—

TDD is a
habit
and a
tool
for building better software. Give yourself room to use it where it helps.


TDD gives you a powerful tool. With experience, you'll get better at judging when and how to use it.

In the final installment, we'll review
everything we've learned about TDD with Spring Boot
and close the series with ideas for what to learn next.

References ๐Ÿ”—

    Applying TDD in Practice โ€” TDD with Spring Boot, Part 14 | PromleeBlog