You Should ThrowYour Unit Tests Away

Joe Eames
Joe Eames
Mar 5 · 2 min read

I don’t mean that you shouldn’t write unit tests. You definitely should.

But you shouldn’t feel bad deleting unit tests when you have some that are no longer relevant. This usually happens due to refactoring, but also happens due to requirements changes. In these cases, your first impulse should be to torch your tests.

If this feels wrong to you, then ask yourself why?

Usually, we hate getting rid of something because it has meaning to us. Things that have meaning to us usually have meaning because of the time we put into them.

So if you hate throwing away some tests, that might just be because you spent so much time writing them. And that’s the key here: if you spent a lot of time writing a test, something is probably wrong.

In the practice of TDD (writing your tests before you write your code) tests have to be cheap and easy to write. TDD is about feeling better. It’s about zen. It’s about flow and coding. Effective TDD reduces cognitive load, and makes coding more pleasant, and faster.

On the other hand, tests that take a long time to write probably took a long time to setup, to understand, and to get correct. In fact tests that take a long time to write may have a reasonable chance of being incorrect. They’re also probably very closely tied in with the code they test. These are all reasons that it takes a long time to write a test, and are all indications that your unit tests aren’t very effective.

For more about this, see my recent video on why you’re probably writing your unit tests wrong.

This often happens because the tests are written afterward, so they’re an afterthought. Whether the code is easy to test or not is coincidental.

So let me make a bold statement here: You get 60% of the value of unit tests when you write them, and only 40% by keeping them around.

This may sound crazy, but when you TDD, it’s crafting the test that helps craft the code and makes the coding easier. It’s the scaffolding that makes building simpler and faster. After the building is built, it can still guide and document and create safe refactoring, but you’ve gotten SO MUCH value out of the test just by writing it, and letting it guide the implementation of your code.

Tests should be easy to write, and easy to throw away. Tests that don’t meet these criteria become friction. Tests that do meet these criteria increase velocity.

If you’re interested in learning more about how to do Test Driven Development in Angular, come attend my one-day workshop on TDD in Angular at ng-conf 2021.

ngconf

The World’s Best Angular Conference

Sign up for ng-conf Newsletter

By ngconf

Get up-to-date info, news, special offers and more from ng-conf! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

ngconf

The World’s Best Angular Conference

Joe Eames

Written by

Joe Eames

Mormon, Christian, Father, CEO of Thinkster.io, Organizer of @ngconf, @frameworksummit, React Conf. Front end developer, and Software Craftsmanship Evangelist.

ngconf

The World’s Best Angular Conference

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store