Categories


Archives


Recent Posts


Categories


Running Magento 2′s Tests.

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

A quick primer on running Magento 2’s development tests. Most of this is just reworded information from Vinai Kopp guiding me through.

If you’re working with the Magento 2 GitHub repository, you can run the project’s unit tests with

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml

This assumes you’ve copied dev/tests/unit/phpunit.xml.dist to dev/tests/unit/phpunit.xml. The phpunit.xml file contains is PHP Unit’s configuration file, which helps test harness developers initialize their testing enviornment. You may need to use this configuration file to set certain PHP ini flags (memory_limits, etc) if your defaults clash with what Magento needs.

You can also run Magento 2’s integration tests. Per Wikipedia, integration testing is

Integration testing (sometimes called integration and testing, abbreviated I&T) is the phase in software testing in which individual software modules are combined and tested as a group.

In the web application MVC world, integration test has become synonymous with

tests that require a bootstrapped Magento enviornment to run

In order to run Magento’s integration tests, you need to point the unit testing framework at a MySQL server, and a specific database on this server. You should not use your own development schema for this, as the integration suite will end up modifying the database while running.

To point the test framework at your database, copy

dev/tests/integration/etc/install-config-mysql.php.dist

to

dev/tests/integration/etc/install-config-mysql.php

and add your credentials to this file. The integration suite also has its own PHP Unit configuration file

dev/tests/integration/phpunit.xml.dist

which you’ll want to copy to

dev/tests/integration/phpunit.xml

and make any needed changes (PHP ini memory limits, etc)

Finally, to run the integration tests, you’ll need to change to the integration test directory, and run PHP unit from there

$ cd dev/tests/integration
$ ../../../vendor/bin/phpunit

Trying to run the integration tests from a different directory (i.e. the root directory) can lead to problems with dev/tests/integration/phpunit.xml is not readable errors.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 14th March 2016

email hidden; JavaScript is required