DEV Community

Marzee
Marzee

Posted on

Why you should advocate for automated tests

How many times have you deployed a new release in a project, and only after merging it to production an urgent bug is detected? This usually happens for lack of testing, for following an incomplete test guide, or for human error.
For continuous delivery projects, where you are delivering new code constantly to your users, automated testing is critical to make the whole process agile. Not just to maintain the quality of the code-base but most importantly to ensure the stability of the web platform throughout its development cycles.

Even though this is well-known in the web development community, it is not always easy to have automated tests as a priority and to convince decision-makers to dedicate time and resources to implement these tests.

We have recently implemented a set of automated tests in a Drupal-based complex platform in close collaboration with our partner Luís Santos from Openquest. As a Senior Drupal Developer working with Drupal for over 11 years, Luís is focused on security, best practices, performance and usability. He was the lead in the implementation of the automated tests for this specific project.

The project was using Headless Drupal 8 for the back-end dealing with all the editorial experience and the front-end we rendered using ReactJS components within Drupal (see our case study). Every time we had to go through a release, we would have to manually test the codebase, which made each release not just time consuming and repetitive but also open to human error. The tester had to check all log files, any external services and confirm if there were any database errors.

Automated tests are very useful to ensure the quality of your projects and are an important part of maintaining high-quality code and software. It is important to highlight to decision-makers that automated tests can reduce or even eradicate these problems, and most importantly it can speed up the testing process.

In general, the objective of the automated tests are the following:

  • To reduce Testing Cost and Time;
  • To speed up the Testing Process;
  • To help improve Quality;
  • To improve Test coverage;
  • To reduce Manual Intervention.

There is a lot of discussion on the best way to implement automated tests and there is a variety of frameworks and types of automated tests. If one considers the test automation pyramid strategy by Mike Coen, there are three different levels of test automation: Unit tests; Service tests (also known as automated API tests, automated component tests, or acceptance tests) and finally the User Interface test.

The base of a fully automated test system is the Unit Tests. Implementing Unit Tests means to break your codebase into pieces, and subject each piece to a series of tests. This enables you to have immediate feedback when a failure occurs.

Alt Text

In the case of our project, the first thing we did was to define a strategy. We leaned ourselves into the code-base and listed all the actions and basic functionalities from the web platform we were working on.

It is important to have in mind that in order to have an efficient testing system, we must list all or most important test cases, and test these cases in various scenarios. It is key to have all the unitary actions, everything we were able to break and isolate whether in regards to API connections or even user interaction.

Once we had a general overview of all the testable unitary actions we researched the best approach to use. Since the back-end of our project was in Drupal 8 we started by implementing a test profile based in Drupal Test Traits, an open-source project launched by Mass.gov that enables you to run PHPUnit tests against your Drupal web site, without wiping your database after each test class.

The main objective here was to use the test environment to run the tests with the existing content. We wrote tests for each separate unitary action of the web platform. For you to have an automated testing system covering the whole system, you need to be constantly adding new tests to each new feature added to your site.

Since the platform had many web-services to render and API connections, the test was supposed to validate the web-services inputs and outputs in all the available scenarios.

The result of implementing automated tests for this web platform was immediate. Once we implemented one of the tests, we found a bug that none of the testers spotted before. One of the APIs that was listing articles in different languages per topic was, in a few cases, delivering a wrong listing which resulted in a few cases of wrong indexing and article listing.

As a web development company, we value the quality of the code we deliver and we always make the case for improvements in the platform's structure and deployment pipeline, especially for complex web platforms that are constantly evolving. Implementing automated tests can be a big step and it can mean a lot of effort (and resources), but it will for sure pay off in the short and long term.

Pyramid Image Source: Test Pyramid: the key to good automated test strategy

This blogpost was originally posted on Marzee Labs blog.

Top comments (0)