Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 29, 2020 12:43 pm GMT

When does TDD make sense?

Over the weekend, I noticed this tweet appear in my timeline:

A bunch of people replied to this tweet asking: Great! But... when does TDD make sense?

Especially on the front-end, this question comes up a whole lot. Front-end programming has a legacy of being unsuited for TDD.

With that in mind, heres a simple set of guidelines that I use to help answer this question.

If...Then...
Youre unsure if TDD makes senseUse TDD if you can (see below for why)
Youre working on a teamUse TDD
Youre writing static pages without behavior, like a marketing siteDont use TDD
Getting to market fast is more important than quality or maintainabilityDont use TDD
Youre unsure of what youre buildingSpike first, then test later
Youre working alone on an unreleased projectDont use TDD
Youre working alone on a released project with usersUse TDD

Interested in why I arrived at these conclusions? Read on.

Youre unsure if TDD makes sense

With enough experience of TDD, you will understand when to apply TDD and when not.

So if you need to ask the question When does TDD make sense?, then TDD makes sense.

You need more experience. You need to get more practice.

Practice doesnt necessarily mean building toy programs. Instead, find opportunities in your daily work to try TDD.

Finding ways to shoe horn TDD into your daily work practice is a whole topic itself, so, for now, Ill suggest just this:

Start small. Next time youve got to add a new component to your React app, try doing it with TDD.

If youre working on a team

TDD is a structure that helps you articulate and outwardly express ideas that would otherwise be locked in your head.

That makes it a great socializing tool for getting feedback early on your designs.

TDD goes hand-in-hand with pair programming (when you work with someone else) and team programming (sometimes called mob programming, which is when an entire team works together in front of one screen and one keyboard).

TDD can also give a speed boost to teams.

Ever experienced how slow the code review process can be?

You wait patiently for feedback and then, when it arrives, you context switch back to make the suggested changes. Then you repeat the cycle. This takes a whole lot of time and its mentally (and emotionally!) draining.

When you apply TDD with others, you pull that feedback process forward, which saves time later on.

If youre writing static pages without behavior, like a marketing site

TDD is about testing behavior. Your marketing site does not have behavior.

Sure, you might want to add acceptance tests for this code, but thats a different part of your development process.

If getting to market fast is more important than quality or maintainability

If you think following TDD will slow you down, and that in turn will lose you money and market share, then dont use TDD. You can always come back to add tests later.

If youre unsure of what youre building

To spike is to write code without tests. Often you do this when youre exploring a new technical domain for the first time. Spike until the point that youre confident of the shape of your code. Then you can start adding tests.

Youre working alone on an unreleased project

If youre building a side project that doesnt have any users yet, and may not ever have any, then Id avoid using TDD unless youre specifically aiming to get better at TDD.

This can be argued two ways. On one hand you could say that TDD will delay finishing, and that translates into a risk that you will never finish.

On the other hand, you could say that without TDD youll end up with low quality software that risks never attaining any users because of the poor quality.

Of course, there are other ways to have a poor quality product other than simply having buggy software. You could build the wrong thing entirely: in other words, something that no one wants to use.

So for me at least, the scales tip in favor of not using TDD. Instead, you should focus on getting a finished first version ready.

However if youre absolutely sure that your project will one day have users, and the use cases and requirements are clear, then start with TDD. Itll save you time later on.

Youre working alone on a released project with users

The moment your side project starts attracting users, then you want to start using TDD in order to save yourself from nasty regressions.

Id love to hear feedback if you agree, disagree, or if this was in any way useful. Go ahead and leave a comment below.

Happy coding!


Original Link: https://dev.to/d_ir/when-does-tdd-make-sense-3obl

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To