DEV Community

Cover image for Test? When to test?
Igor Duca for Sig

Posted on

Test? When to test?

Everyone now and then talked about the importance of writing unitary or implementation tests, but not everyone tried to explain to you what do you need to test.

Test? When to test?

First things first I need to explain to you deep down in the basics: "what is the purpose of testing?". Testing is trying to predict a mistake from the user before it happened. As a scientist or an engineer, your job is to prevent the final user to fail in what you have built.

Front-end tests

Front-end tests are sort of more unusual than the back-end ones are.
There are some architectures like microfrontend, componentization or atomic design that could help you creating tests for your websites or front-end applications. Basically, in front-end, you may test the steps that the user will take during his exploration through the website. So, you may want to test things like:

  • Is the register working?
  • Is the login working?
  • Is the document upload working?
  • Is the payment gateway working?
  • Are my emails being sent?

And there are also a lot other kind of tests that not even everyone knows:

  • Testing page contrast
  • Testing page analytics
    • How much time does the page needs to load?

Back-end tests

Back-end tests are kind of required to build an application that can scale this days. This tests may be also related to what the user can, and will do, while he is using your services, so back-end tests must test YOUR code, not the code from the libraries you are using.

For example, a tweet of mine motivated me searching for better explanations about testing, and consequently, made me write this article.

Tweet

As you guys can see, this is an example about WHAT NOT TO TEST, but first let me explain why not to write tests like this.

Only test your code

There are not any problems in the code, the code is pretty clean though. The real problem is: I am only testing Jest's code, not mine.
This test case below only tests if mongoose save method is working, not integrating my application into it.

When to test back-end

Woovi.com have a pretty great article that explains how and when you can test your back-end, you can see it here.

But, basically, you should test your code and the integrations that it may establish with external APIs for instance.

  • Test if API version match to the one you are waiting for
  • Test if your credentials are still active
  • Test if your controllers are working
  • Test if your services are working
  • Test if your recent migration is still compatible with your expected interfaces

Finally

Test your own code.


Sig Coding
Sig is a community-first DAO startup that produces SaaS applications powered by its own community. We spend time thinking on how to make things better and how to make tech be more environment-friendly.


Thumbnail by Wu Yi at Unsplash

Top comments (0)