loading...

Why you should test your app

pedroapfilho profile image Pedro Filho ・2 min read

I know many of you write tests daily and have 90%+ test coverage on your apps (hopefully), but this article is for those who don't, those who don't see the benefit in testing your app (Yep, I have to explain it more then I would like to)

Let's go back to the point. I'll list here the "main" reasons why you should test your app:

You should create things for users, not for yourself

Through my career as a software engineer I had to explain this concept more times than I would like to:

You are not the owner of the product, the user is.

And you may think: "What does it mean? Why this phrase is important for me to understand tests?" And here is the answer: The user doesn't care about the technology you used, neither if your code follows the latest standards, he just wants it to work.

So just imagine that what you "tested" by yourself is 1% of what the real user is going to do, he'll never click the correct button, never, ever, clear the session storage when he sees a bug, he'll just leave swearing, that's what they do.

I bet this next one is gonna make you smile

Refactoring should be easy

I'm a frontend developer, I work with React on my daily basis, and I have to say: Oh boy!

Over these years I saw the same component be done at least 6 different ways, with more optimizations and abstractions, and it's cool, isn't it? But did you ever felt that chill when you had to refactor something?

Let me tell you a secret: You shouldn't.

Refactoring is natural, it's the way software development works, and you should feel confident refactoring your code, and here's where testing shines, as Kent C. Dodds said once on his twitter:

The more your tests resemble the way your software is used, the more confidence they can give you.

With automated tests, you'll be able to say that your component is 100% "compatible" with the last one, and this is exciting isn't it?

You're not the only one that will touch that piece of software

This one is pretty obvious but I have to say: When you work in a company, you have coworkers. People won't read your mind to change your code. Without tests, they don't have parameters to know if they screwed it or not.

Besides, it's almost impossible to be hired without knowing how to test something (at least you're a junior or doing some kind of internship).

Composition, right?

So let's pretend you're creating a page for your app, and this page depends on a button. Are you completely sure that if you change the functionality of that button, it'll continue to work on that page?

And how many pages/containers/components use that button? How can you be so sure that it works everywhere?

The short answer is: with tests

I made a workshop last month to give more examples (React), if you want to check it out: https://github.com/pedroapfilho/testing-workshop

Posted on Oct 7 '19 by:

pedroapfilho profile

Pedro Filho

@pedroapfilho

Curious by nature, entrepreneur and JavaScript enthusiast.

Discussion

markdown guide