Close [x]

Run unit tests

Edit this page on GitHub

Contents

Overview of unit tests

This command runs a set of unit tests defined in the Magento 2 code base. You can either run all tests or tests you select.

Whenever a not supported type is specified, the program terminates and lists all available types.

Following execution, a detailed report displays showing the test run and results.

Prerequisites

Before you run this command, all of the following must be true:

  • The Magento_Developer module must be enabled. You can enable it as follows:

    magento module:enable [--force] Magento_Developer
    

    Use the --force option only if it鈥檚 necessary.

  • Your system must be set up to run the desired tests.

    For example, to run integration tests, you should copy dev/tests/integration/etc/install-config-mysql.php.dist to dev/tests/integration/etc/install-config-mysql.php and modify it to suit your environment.

First steps

  1. Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.

    If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command at the same time:

    su <Magento file system owner> -s /bin/bash -c <command>
    
  2. To run Magento commands from any directory, add <your Magento install dir>/bin to your system PATH.

    Because shells have differing syntax, consult a reference like unix.stackexchange.com.

    bash shell example for CentOS:

    export PATH=$PATH:/var/www/html/magento2/bin
    

You can also run the commands in the following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

<your Magento install dir> is a subdirectory of your web server's docroot. Need help locating the docroot? Click here.

In addition to the command arguments discussed here, see Common arguments.

Run unit tests

Command usage:

magento dev:tests:run [--all] <test>

To list the available tests, enter

magento dev:tests:run --help

For example, to run integration tests, enter

magento dev:tests:run integration