React developers: TDD is not dogma

Daniel Irvine šŸ³ļøā€šŸŒˆ - Jun 26 '20 - - Dev Community

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! šŸ™

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player