Magento 2 How to Run Unit Tests via Command Line

In this tutorial, we will talk about How to Run Unit Tests via Command Line in Command Line Series. As you know, from Magento 2, they add many commands in bin/magento. This may difficult to get approach this, let me explain more detail about How to Run Unit Tests via Command Line.

How to Run Unit Tests via Command Line

Go to Magento admin root folder and show usage:

php bin/magento dev:tests:run --help
  dev:tests:run [options] [--] [<type>]                                                                                     
  type                       Type of test to run. Available types: all, unit, integration, integration-all, static, static-a
ll, integrity, legacy, default [default: "default"]                                                                         
  -c, --arguments=ARGUMENTS  Additional arguments for PHPUnit. Example: "-c'--filter=MyTest'" (no spaces) [default: ""]     
  -h, --help                 Display this help message                                                                      
  -q, --quiet                Do not output any message                                                                      
  -V, --version              Display this application version                                                               
      --ansi                 Force ANSI output                                                                              
      --no-ansi              Disable ANSI output                                                                            
  -n, --no-interaction       Do not ask any interactive question                                                            
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 

  Runs tests

Syntax to Run Unit Tests

php bin/magento dev:tests:run [options]

Simple run tests

php bin/magento dev:tests:run 


Tests: 4163, Assertions: 14590, Errors: 6, Failures: 29, Warnings: 1, Skipped: 173, Incomplete: 1.
FAILED - 4 of 5:
 - dev/tests/unit> /usr/bin/php7.0 ./vendor/phpunit/phpunit/phpunit
 - dev/tests/static/framework/tests/unit> /usr/bin/php7.0 ./vendor/phpunit/phpunit/phpunit
 - dev/tests/integration> /usr/bin/php7.0 ./vendor/phpunit/phpunit/phpunit
 - dev/tests/static> /usr/bin/php7.0 ./vendor/phpunit/phpunit/phpunit

Enjoyed the tutorial? Spread it to your friends!


Sam Thomas
Sam Thomas

CEO and Founder of Mageplaza. Pursueing a simple and healthy lifestyle. A friend, a husband and a dad of two children, a trainer and an influencer wannabe. He is a big fan of sports and travel, also.