Profile picture
Andrew Culver @andrewculver
, 7 tweets, 2 min read Read on Twitter
I’m going to quote anonymously from someone who deleted their tweet: “It’s easy to write untestable code which is why writing tests first guards against that.” This is a super common argument for doing TDD, but when you dig into it, it’s actually circular logic. 🙇‍♂️
“It's easy to write untestable code" is only true if you insist on testing things in isolation at a unit level. In practice, I find even the most abhorrent one hundred line methods quite testable with headless browser tests, regardless of how the code is structured.
I’ll give you a concrete example: github.com/andrewculver/k… . I, admittedly, wrote this method. It’s the bane of many developers, and infamous among it’s users, but in the six years since I wrote it, it’s helped facilitate at least ten million dollars in Stripe subscriptions.
Furthermore, despite being 121 lines long, it was trivial to achieve complete test coverage (when developing Bullet Train) using a series of steps in a single headless browser test. This method is *only* difficult to test when you insist on testing at a unit level in isolation.
So this whole argument about doing TDD to promote writing “testable code” falls really flat amongst folks like myself who favor headless browser tests. The vast majority of code is testable by default if you’re not concerned about testing in isolation.
In situations where something isn’t easily testable with feature tests, by all means, write a lower-level integration test. And if an integration test doesn’t do the trick, then go ahead and write unit tests. And if it’s hard to test, by all means, refactor so it’s “testable.”
But to say you should do TDD because it promotes writing code that is testable in isolation, that’s circular logic, because you only need that code to be testable in isolation because you’re doing TDD. 🔁
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Andrew Culver
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!