Blog hero curve

MARÍA NOEL REISSIG | September, 2022

A simple guide to understand Testing

Different types of testing that will improve your code quality

Technology

When we first hear about Testing we think about manual testing, done by a person checking each part of our application manually. However, we should test it automatically to avoid human errors, save time and simplify processes, especially when we change or introduce a new part of code in our application.


We have three different ways of testing our code automatically:

  • Unit Testing

With the unit tests, we expect that each of our components does its work correctly, regardless of their relation with other parts of the code.

  • Integration Testing

In this type of testing, we hope that our components work together without any problem. Now, how do the components work together? The answer is that they are communicating with each other by the data and the events they are sharing.

  • End-to-End Testing

When we do End-to-End tests, we are testing our App in an entire situation. To do this, we create scenarios. For example, let’s say we have a form with an Email input. We expect if the user submits the form without filling in the Email input, they will get an error message.

When should we use Unit Testing?

Unit Testing are fully isolated tests. The purpose of unit testing is to validate that each unit of the software performs individually, as designed. The more tests we can do of this kind, the better. They are pieces of codes that test other codes.

Suppose we want to test the correct behavior or expectation of a part of our code under a controlled environment. In that case, we should simulate everything that comes from an external point.


So when we talk about unit tests, we test individually by simulating what we should expect from that individual piece of code.


What JEST has to do with all of this?

JEST is a framework for testing created by Facebook, built on JavaScript, that provides resources for writing and running tests.


Often, unit tests for the front-end require extensive, time-consuming configuration. This complexity can be reduced to a great extent with the Jest framework because it is not only well-documented, but also requires little configuration and can be extended to match your requirements.


Jest stands out because of its simplicity, making it an ideal tool for testing JavaScript Projects.

"Jest is a delightful JavaScript Testing Framework with a focus on simplicity." Source: jestjs.io

Jest uses a custom resolver for imports in your tests, making it simple to mock any object outside of your test 's scope.


What is Mocking?

Mocking is a process used in unit testing when the unit has external dependencies.


The purpose of mocking is to isolate and focus on the code being tested and not on the behavior or state of external dependencies. Its use allows you to create a fake version of an external service or dependency, simulating the real one and helping your tests run more quickly and reliably.


So in simple words, mocking is creating objects that simulate the behavior of real objects.

Let’s talk about integration tests

Integration testing is a type of testing that checks the combinations of different units, their interactions, how subsystems unite into one common system, and code compliance with the requirements.

For example, if we think of an Ecommerce app, we can check the ability to log in or sign up after users add items to their basket. In this way, we can test if the integration between these two functionalities is working correctly.


Integration testing and unit testing are two levels of software testing:

Unit testing implies checking the smallest functioning parts of code separately, meanwhile integration testing goes further as we look for errors that happen when units start interacting.


The fact that units have successfully passed the tests at the previous stages doesn’t guarantee that they will work well together.


To wrap it up, unit testing is the examination of the smallest functional parts of code. Integration testing is the examination of the smallest possible combinations of those parts.

End-to-end tests

End-to-end testing uses a production equivalent environment and data to simulate real-world situations and may also involve your software's integrations with external applications.

It is recommended to have a few crucial end-to-end tests and focus more on lower-level testing forms to find breaking changes (unit and integration tests) quickly.


What is Cypress?


Cypress is a testing framework for both integration and end-to-end testing. As you develop a test, you can watch it run in the browser, and afterward, inspect specific elements at a past step, rewind to see why your selector did not select what you expected, and more.

To sum up

Obtaining solid test coverage is imperative for building confidence in your web application.


Even though each sort of testing uses a different technique, they all have the same goal: see if the outcome of a code execution fits a set of criteria. In this manner, they are complementary, and when used together, they may provide you with the complete trust you require in the operation of your software.


When it comes to deciding what tests you want to run when testing your products, the decision will depend on your budget and the aspects of the application you're testing. The answer will change on a case-by-case basis, so it's best to learn more about your options and their differences.


We'd be happy to lend a hand if you're still struggling to decide whether you need end-to-end or integration testing. Get in touch with us to know more about our development services 🚀

Share:

María Noel Reissig
✍️María Noel Reissig

September, 2022

Testing simplifies changes in the future, especially when different developers are working on the same project. They also work as documentation. Testing should be a major part of our code and is encouraged when we want to grow as developers, as Tests improve our code quality.