Automated tests and test pyramids in Magento 2 – check which can be useful

Software testing is a long and complex process. In the contemporary world, maintaining a high-quality product using only a manual approach to testing is difficult. Frequent changes that can affect large parts of the system require automation of certain areas. An agile approach to software development involves testing from the earliest possible stage of the project. This allows you to identify incompatibilities, defects or glitches, the fixing of which is often faster, easier and cheaper as a result. Automated testing should take place at every stage of software development.


What is a test pyramid?

The use of the test pyramid fits very well into the approach described above. This solution relies on the assumption that the product should be tested automatically using different testing levels.

Individual tests form a kind of a pyramid. The base of the pyramid starts from unit tests, through integration tests, APIs all the way to E2E tests (UI layer). Manual tests are above the pyramid and complement it.

The pyramid includes the biggest number of unit tests (tests performed by developers during code development). They are fast, performed in isolation, and enable to detect bugs at an early stage, which results in a lower cost of fixing them.

At the very top of the pyramid are E2E tests. These tests are much slower, they test specific business cases, are more expensive and time-consuming to maintain. They use the UI layer (reflect the user’s interactions with the application). A single test can include a specific business path, which can result in a long test run time. E2E testing should not be excessive.

Magento 2.x Automated Tests

Magento 2.x provides a suite of tests to automatically control your application quality. They are a good complement to the testing process. The suite includes the following automated tests:

  • static – static code analysis for compliance with Magento 2 coding standards and best practices;
  • unit – tests verifying the correctness of the code (are created in the course of development), performed in isolation;
  • JavaScript unit tests – they test the frontend code of the application using Jasmine framework;
  • Integration tests – they test the code in varying degrees of isolation. They tend to be a lot more low-level than functional tests. Because they do not use a browser, they can run faster;
  • Web API functional – allows you to test Magento Web API from the client application’s point of view;
  • functional – black box tests, performed from a user perspective.

The above tests apply to the core part of Magento. It is definitely worthwhile to learn more about them and to consider using at least some of them in your project. They can offer many benefits because:

they test Magento’s core, so they can be helpful in creating new modules (they allow you to verify whether the newly developed modules have not adversely affected the core part of the application);

they are educational materials – you can use them to learn about Magento’s approach to testing.

On the other hand, when deciding to try the above tests, you need to be patient and allocate more time, especially at the beginning. Finding your bearings with such a big number of tests is time-consuming.

When analyzing the above automated tests, you may also encounter difficulties such as:

– the need to adapt the tests to your application. Some elements may not be available, so not all tests will be right for you;

– the need to verify the settings – the tests are prepared for a specific frontend template and use a specific language (e.g. in assertions based on the content of pop-up messages). Applications with settings may experience problems.

The tests in Magento 2 constitute an interesting element for development as part of the test pyramid. The test levels shown above are only a basis for building such a pyramid.

Summary:

Applying different levels of testing in the software testing process is important and helpful. It’s a good idea to start testing your project as early as possible. Maintaining product quality should be the goal of the entire team, as not all areas are within the control of the tester himself. It is definitely worth trying the solutions available on the market which can support the testing process or provide knowledge on how to do it better.

Our Experts
/ Knowledge Shared

14.09.2021

QlikSense vs Power BI / A Not So Unbiased BI Software Comparison

Power BI

The Business Intelligence market is vast – there are many options and it’s estimated that no one solution owns more than 20% of the market. In other words, there’s no clear winner – but are there losers? Well, as the title suggests, we want to use this space to talk about QlikSense vs Power BI (the former being the...

07.09.2021

Digital Accessibility & Usability / Adapting to the Customer

E-Commerce

In our previous post, we discussed the challenges of making websites more accessible for people with vision impairments and (spoiler) how to solve them. This time, we want to expand on the concept of usability as a whole, to show how businesses can better make their products and services accessible for all. This time, we want to talk about:...

31.08.2021

Digital Accessibility & Usability / A Visual Overhaul

E-Commerce

Nearly every industry these days has an online element – in some cases, it’s the predominant channel. And that’s great – if you don’t have any accessibility requirements.  But as more and more of the world moves online, we need to consider the wider needs that different people may...

Expert Knowledge
For Your Business

As you can see, we've gained a lot of knowledge over the years - and we love to share! Let's talk about how we can help you.

Contact us

<dialogue.opened>