Testing – why is it so important and how you can benefit from it?

The topic seems quite obvious and many developers have either heard something about tests or know very well what they are, but unfortunately they still do not use them in their projects. It’s often due to lack of time / budget for such an undertaking. However, in our opinion, it is worth investing some time in software testing, because it will certainly pay off in the future.

We would like to emphasize how important software testing is and what benefits does it bring, based on our projects, where we designed a REST API.

Most mobile applications communicate with servers to retrieve data. These servers contain databases. In order for the communication between the mobile application and the server to run smoothly and for the programmers of both platforms to be able to communicate, an API is created based, among others, on the REST architecture, where:

REST – Representational state transfer – an architecture that is based on stateless communication.

API – Application Programming Interface – the style of architecture for distributed systems, which uses, among other things, a homogenous interface.

In this article we will focus on maintaining the API at a high level and on its dependability. End-to-end functional tests will be helpful here, so we will discuss them as well. (Of course there are many more test levels and types of software tests).

What is testing in general?

Software testing is a process that is responsible for its quality. Testing is proceed to verify and validate software. Verification is checking if our software complies with the specification. Validation, on the other hand, verifies whether the software complies with the business assumptions.


Our path of action

Together with our team, we decided to invest in functional tests, or more precisely in end-to-end tests, because we believe that they provide the most benefits with little time and effort.

For end-to-end testing in our projects created in PHP (based on Symfony framework) we use Codeception. It is a framework, thanks to which we can easily create unit, acceptance or functional tests. Tests in Codeception are written based on BDD (Behavior Driven Development), i.e. creating short stories that simulate user behaviour taking into account extreme cases such as when something unexpected happens.

Codeception helps us create two types of tests for our REST API:

– unit (here Codeception uses the PHPUnit library)

– end-to-end functional tests.

We believe that using such tests allows us to maintain the API at a high level of dependability. Covering the business track with tests together with all the extreme cases strengthens our conviction that the business assumptions will be maximally fulfilled. 

Our policy of creating tests within the backend team is based writing the most valuable tests at the lowest possible cost.

We focus on creating unit tests only for important or complex functionalities. We do not want to cover unit code with tests at the level close to 100%. Maintaining and developing such a meticulous approach would take too much time and could eventually lead to project unprofitability. Additionally, unit tests do not verify the business level of the application. 

However, in functional tests we focus on the ‘end-to-end’ approach, where it works well for API endpoint testing. In case of ‘end-to-end’ tests we try to cover all API endpoints with all possible scenarios. Such an approach, compared to covering all software unit tests, takes much less time and still ensures high software quality. Test scenarios define our business processes. 


The benefits of testing

Thanks to the tests we have a very low number of mistakes. It’s extremely rare that a bugfix task gets into our incident board. It’s due to the fact that API testing at the level of implementation of new functionalities verifies the status of the whole project. 

Example of implementation of functional test in one of our projects:

In this test, the correct user login path to the system is verified, as a result of which the user receives an “access token”, which they can then use to receive access to specific resources.

Such a strategy allows us to maintain high level of API at low business cost. We developed it some time ago and it works well for us. We don’t think that this approach is the best in every respect. We don’t encourage you to write tests in our style either, however, we do encourage you to write some tests! This has already paid off for us many times, e.g. when some changes in the software caused problems in a part of the system. Thanks to the tests, they were detected very quickly and did not land on production. 🙂


Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *