When Test-driven Development Clicks

twitter logo github logo ・1 min read

Test-driven development (TDD) is a tremendous approach for writing reliable software programs, but it's not a tremendously intuitive one. I recently asked the question What was your TDD aha moment? and I want to share the top comment, which provides good insight into the subject.

One of the biggest "aha"'s I've had was when working on a legacy codebase with very few unit tests.

I needed to change the behavior of a couple of methods, but I wasn't super sure what their current behavior was to begin with.

A lot of folks would reach for their debugger and spend the next while meticulously stepping through the code. But that felt slow to me...

So I put together a suite of tests around them (prior to making any code changes) to verify and document what they were really doing. Once that was done, the overall change was as simple as adjusting a couple of assertions, causing those tests to fail and reimplementing the methods to meet their new expectations.

It's one thing to see TDD as a way to confidently write a brand new feature, it's a whole other ballgame to see it as a way to confidently navigate and tease apart legacy code. It was like being in a super dark tunnel, and finding a flashlight. Literally everything got easier.

And don't even get me starting on working on an old codebase with a good suite of tests. Pure. Bliss.

Early in my software career I struggled with imposter syndrome over the fact that TDD had not clicked for me. It's okay to not TDD. Most developers do not use this approach.

TDD is one of the finer approaches for software development, but don't stress if it has not clicked for you.

If you're interested in getting started with TDD, this post may be helpful:

twitter logo DISCUSS (9)
markdown guide
 
 

I prefer Test Support First not Test First.

Respect test value and design support test first, not much magic here we only need Dependence Injection, so we can mock when we need test.

So after verify our design can support test, we focus on code features. When need or happy we can write one or two tests.

TDD is too heavy word.

TSF no TF.

 

Sorry, off topic but not worth a new topic. How do we embed a dev.to post like that?

 

You can do that by using Liquid tags. Type in {% link <insert the URL to your DEV.to post here> %} in the editor. Seek the Help section whenever you "Write a Post" for more built-in Liquid Tags for embedding content.

 
 

How does one do TDD when the majority of the work is front-end web dev?

 
 
Classic DEV Post from Oct 31 '18

How a Month without Computers Changed Me

I’ve sent a message to my family and delegated my open source projects to my friends. With my last tweet sent, I turn off my laptop, phone, and tablet. My Digital Sabbath begins in 10 minutes: no digital devices for the next month.

Ben Halpern profile image
A Canadian software developer who thinks he’s funny.

Hey there reader...

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️