Why you should test both frontend and backend.
Tags: testing, frontend, backend
Published: 2020-08-25 23:06:59

Hey! This is my first post in here, my name is Sergio and I am a web dev. Anyways, I will try to keep it clean and nice :laughing:

So... We all have been there, you have finally finished that assignment that was driving you crazy, you see the light at the end of the tunnel, but suddenly you remember the bad part of programming, **TESTING**.

![Testing GIF](https://media0.giphy.com/media/gw3IWyGkC0rsazTi/200_d.gif)

There are difficult opinions about it in the dev community, it is praised by some and hated by others. However, even if you are in one or another side, at the end of the day you know it is a necessary step to ensure our application is running and is functioning correctly.

( Yes, yes, we sometimes run out of time and there is no way tests are possible, we all know that feeling unfortunately... :disappointed: )

This topic came to my mind as I was browsing **StackOverflow** in search of questions to answer and help some people out, and this one caught my attention, it came as following: 

"**Do both: Front-end and Backend Unit tests?**"

Basically, OP was asking if both front and back-end testing is necessary. 

This is a common discussion topic, there are web devs that do back-end testing, others that do front-end testing, and others that do both, it mostly depends in what area you are developing and what are your company's policy (hello there fellow freelancers!). 

However, as a dev, I think that we get more benefits from doing testing than by not doing so. 

First of all, you make sure that your piece of work is working as you expected, and that there are no flaws on it. You can even try to test by doing mocks with different types of data, and try to get the result, this could be achievable with [*Postman*](https://www.postman.com/) by doing simple JavaScript tests.

![Testing cats](https://www.chinosity.com/wp-content/uploads/2019/05/yas-cat-gif-1.gif)

There is a cool feature in Postman, it is called *Runner*, it lets you write and run the tests, **ALL AT ONCE**. You can see if the tests have passed the requirements you have stipulated before, by checking the body and code of the response. 😎

Furthermore, if you are using *Laravel/Lumen* to create your API you can take advantage of their own [unit tests](https://laravel.com/docs/7.x/testing). If you are able to perform both Postman and unit testing and all your test turn out well, congratulations you have got a bulletproof API!

After you have made sure that your API is good to go, you can take a step ahead and test your front-end, this is basically doing mockup tests just by yourself or doing it the cool way with [*Selenium*](https://www.selenium.dev/) 🤓

*Selenium* is good to go to test the functionalities of your web app, the tests can be written in languages like Java, PHP, C#, etc. It performs end to end testing across various browsers and platforms like Windows, Mac, and Linux.

![Selenium testing](https://media-exp1.licdn.com/dms/image/C5612AQHmfnLiLkBIVw/article-cover_image-shrink_600_2000/0?e=1602720000&v=beta&t=h8QRzZp2lxjgnAbGStLao3n1aLRCD2UKtcsNuFHkCqM)

So once you are both done with your front and back-end, and you made sure that all your tests have passed, you are ready to go and deploy the app!

*What are your thoughts about testing?* Do you like to do it or are you one of those devs that hate it? Tell me your thoughts below.

Until the next post! Happy coding! Sergio. 
🥰 🤓

(If there is anything that bothered you while reading, tell me so I can improve it in my next posts, thank you very much!)