Reading list Switch to dark mode

    Commands to perform unit testing in Magento 2.

    Updated 4 January 2023

    This blog will aware you about the Execution of the unit tests in Magento 2.
    Before proceeding further let’s get familiar with PHPUnit .
    Here are few wonderful blog links that can help you understand or have Idea faster.

    Hope now you have an Idea about the PHPUnit and Unit testing.

    Today I am going to share the few commands with which you can execute the Unit Testing.
    But ,
    NOTE : The Magento_Developer module must be enabled.
    1. If you want to Execute all the test cases, then use the below command.

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


    php bin/magento dev:tests:run

    NOTE : But the above commands takes too much time.

    Searching for an experienced
    Magento 2 Company ?
    Find out More

    So We need some thing which is faster , so the solution is to execute the Unit Tests module wise, so below is a command that can help you with.
    2. If you want to Execute the Unit tests with specific Module :  Ex :- magento-catalog .

    php vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/magento/module-catalog/Test/Unit/

    Magento 2 Uses PHPUnit Package to run Unit Tests .
    Basically PHPUnit automation testing framework has been included as a Dependency in Magento 2’s composer.json file.

        "require-dev": {
            "phpunit/phpunit": "~6.2.0",
            "squizlabs/php_codesniffer": "3.1.1",
            "phpmd/phpmd": "@stable",
            "pdepend/pdepend": "2.5.0",
            "friendsofphp/php-cs-fixer": "~2.2.0",
            "lusitanian/oauth": "~0.8.10",
            "sebastian/phpcpd": "2.0.4"
        "autoload": {
            "psr-4": {

    Command Format :
    {phpunit_executable} -c {Magentoroot}/dev/test/{type}/phpunit.xml[.dist]  path/to/module/test/dir

    This blog is just to have the hands-on Experience to run test of core module.

    In Next blog we will learn how to create Custom Module’s unit Test in Magento 2.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home