DEV Community

Cover image for React developers: TDD is not dogma

React developers: TDD is not dogma

Photo by Tomek Baginski on Unsplash

โ€”โ€”

Update: Kent replied to this article and was kind enough to explicitly tweet the following about TDD, which then provoked a great discussion from his followers. Thank you Kent!

The original article is below.

โ€”โ€”

A couple of days ago, Reactโ€™s leading educator on testing wrote a tweet about test-driven development (TDD) that displayed a common misunderstanding:

This is a back-handed compliment that relies on the belief that TDD is dogma (and if you read the parent tweets, also on the belief that using TDD/BDD doesnโ€™t result in valuable tests).

Iโ€™m highlighting this because I worry that a whole generation of programmers will miss out on learning a valuable skill because of the strong words from their respected peers.

I worry that people will read this and think โ€œKent doesnโ€™t use TDD, therefore TDD must be bad.โ€

It is also a risk to the ongoing adoption of React if the community fails to embrace an important industry technique.

Personally speaking, using TDD gave me a huge boost in my career as a software developer. Without TDD I wouldnโ€™t be a successful independent consultant. It has helped me write high-quality Windows desktop applications in C#. It has helped me build backend monoliths and microservices in Ruby, Java and Clojure. And of course, Iโ€™ve also used it with success on the frontend: not just with React but other frameworks, with vanilla JavaScript, and with ClojureScript too.

TDD is here to stay

TDD has been around for decades and is a natural progression for developers who are interested in testing.

When you start writing tests for the first time, you are bound to make mistakes. The more mistakes you make, the more you learn about โ€œgoodโ€ testing practice. Eventually you learn about TDD, and suddenly you become slightly embarrassed about everything you did before.

TDD is anti-dogma

The TDD process is not dogma. In fact, learning to cheat at TDD is part of the fun of TDD. (But you canโ€™t cheat until youโ€™ve practiced the game so much that you know the rules by heart.)

TDD is disciplined. TDD says that every single line of code your write must be written with thought and care.

The reason that TDD is anti-dogma is that if you apply TDD, then you can write your code whichever way you like. Nothing is out of bounds. As long as the tests pass, youโ€™re good.

And if the tests are passing, youโ€™re free to refactor your code however you like.

TDD is social

TDD, combined with pair and team programming, offers a process that allows teams to combat some nefarious team problems: siloed development and overly-complex code are two that spring to mind.

TDD helps a team perform at a consistent rate. In agile parlance, people talk about consistent velocity being a sign of a high-performing team, and thatโ€™s what TDD helps teams achieve.

TDD is for beginners, too

There are coding bootcamps--like Makers in London--that teach TDD to new recruits. Group learning combined with tuition from experts is a fabulous way to learn TDD. And developers who graduate from TDD bootcamps are highly sought after because of their skillset.

Our community is full of dogma. Be careful!

The React testing community is actually very fond of dogma: Stop mocking fetch! Donโ€™t use nested describe blocks!

To be clear, this is what dogma looks like.

One trick that has kept me well informed over the years is remembering that anytime someone tells you categorically not to do something, they are stating an opinion based on their lived experience, not fact.

Unfortunately in computing, itโ€™s very common to see developers conflate something that is valid for their lived experience with what is valid for everyone. โ€œThis didnโ€™t work for me, therefore it canโ€™t work for anyone!โ€

The best we can do as teachers is to say: โ€œHere is something that works for me, and hereโ€™s how I like to do it.โ€

Iโ€™m not asking you to use TDD

Remember that in the grand scheme of things, the React community is still an infant. Itโ€™s still learning about the world. It has much to learn from the rest of the industry.

Iโ€™m not asking you to use TDD. Iโ€™m asking you to keep an open mind.

Happy coding! ๐Ÿ™

Top comments (9)

Collapse
 
martinrojas profile image
martin rojas

Great article!!

I am an experienced developer, but sadly testing has been a place where all my professional projects have been an afterthought because there is always a QA person dedicated to writing tests. Do you have any sugestion on some resources on TDD.

Collapse
 
d_ir profile image
Daniel Irvine ๐Ÿณ๏ธโ€๐ŸŒˆ

Kent Beckโ€™s books are a great starting point. What language(s) do you work with?

Collapse
 
martinrojas profile image
martin rojas

JavaScript mostly, and right now I have been working on React to fully Master

Thread Thread
 
d_ir profile image
Daniel Irvine ๐Ÿณ๏ธโ€๐ŸŒˆ

You can always check out my own book for learning React TDD (see my bio for info). Another amazing book that helps with getting the same mindset is 99 Bottles of OOP by Sandi Metz--Iโ€™d recommend reading that for sure.

Collapse
 
shadrack1701 profile image
Matt Trachsel

"anytime someone tells you categorically not to do something, they are stating an opinion based on their lived experience, not fact"

That's not what Kent did, so I'm not sure why this article was written. People should use whatever methodologies are best for them individually. Try TDD by all means. But the claims you write better code/are a better developer because of it are to quote an article I just read: "an opinion based on their lived experience, not fact"

Collapse
 
d_ir profile image
Daniel Irvine ๐Ÿณ๏ธโ€๐ŸŒˆ

Thanks for taking the time to comment.

You are correct on the last part. Almost everything you read about in programming is an opinion. I am glad that you took that last quote to heart, itโ€™s a key point. โค๏ธ

The first statement you mentioned was a comment about that tweet but about other things Kent has written, for example recently he told people to avoid mocking fetch and use a fake object library instead. Mocking fetch is a perfectly valid testing technique that I and many other coaches have been teaching for years, so when Kent writes an article about his lived experience as if it were fact, it takes a lot of extra work to undo that message, because the people weโ€™re coaching get confused about who to listen to and whoโ€™s โ€œrightโ€. Obviously thereโ€™s no right (see above) but it takes time and energy to have that discussion, which gets tiring when it happens again and again.

Thatโ€™s why this article was written.

Collapse
 
siy profile image
Sergiy Yevtushenko

Great article!

By the way: there are many areas in software development which still in their infantry. For example bare metal embedded apps often look like they were written 30-35 years ago.

Collapse
 
d_ir profile image
Daniel Irvine ๐Ÿณ๏ธโ€๐ŸŒˆ

Great point. I donโ€™t know anything about embedded apps but Iโ€™m guessing itโ€™s a lot of C?

Collapse
 
siy profile image
Sergiy Yevtushenko

Usually yes, but recently there started to be visible significant rise of use of C++, especially templates. Testing is still sparse at best, although book Test Driven Development for Embedded C is almost 10 years old. Overall software development is very conservative in some aspects, especially in adoption of new techniques and practices.