Browse Cities

Tips on Running Magento Integration Tests

Integration tests examine how various components, layers, and an environment interact. The dev/tests/integration directory contains these. Magento uses PHPUnit for integration tests, much like unit tests. Therefore, the difference between a unit test and an integration test is more of a logical nature than a technical one. Magento integration API uses a different Magento installation on a separate database for testing purposes. It automatically utilizes the entire project’s codebase, including all active modules. Before running the first test, all setup scripts are run. Besides this, here are a few tips from Magento experts to run integration tests:

Set up the framework for integration testing.

You must establish and set up a test database before you can run integration tests on it. You could also change the PHPUnit setup based on your needs. Before using the integration test framework for Magento, you should set up the test environment. The following are requirements for the test environment:

  • A dedicated database for integration testing:

Every time you try to run a test case, the framework will install a new Magento test database. Avoid using the same Magento database to prevent data loss, like products, order summaries, customer details, etc. It is advised to execute the tests using a specific database user for safety reasons. No additional databases should be accessible to that database user.

  • Configuration of test framework database:

Add your test database access credentials by copying the Magento configuration file. Avoid .dist suffix while copying the file. When the Magento integrations execute the command ‘setup: install’, every array key will pass an option argument. Utilize the database login information for your test database.

Magento offers a file template for customized entries in the core config data table, such as adding new third-party services that fundamentally alter your application or configuration for logic that would restrict access if not configured correctly.

Add your path-value pairs after copying the global configuration file. Removing existing entries from the file would prevent the Integration Test Framework from running tests as intended.

  • Modify the PHPUnit configuration file

For information on the default integration test configuration, refer to the PHPUnit configuration file. Copy the default file without .dist and make your modifications and configuration changes. Your modifications won’t be overwritten in this manner during Magento upgrades. The file contains several settings. But you need to configure only three of them, tests cleanup constant, PHP memory limit, and rabbitmq_management_port constant. 

Perform third party integration tests

Extensions from third parties are housed in a separate directory and may include unique integration tests. These tests are often found in the module folder’s Test/Integration/ subdirectory. The default integration test configuration does not detect these third-party integration tests. Add a configuration to your test suite to incorporate them during test execution. 

The Takeaway

Other common tips for executing integration tests are running tests in CLI (Command Line Interface) and PHPStorm. These tips will help you speed up the initialization time and smoother the continuous integration process.

Related Articles:

We want to ensure your brand delivers a best-in-class shopping experience.

Let’s Talk.

Start with a conversation. From there, we can build a plan.


    Book A Time

    Let’s get something scheduled.