Shopping cart

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!


Comments for Magento 2 How to Run Unit Tests via Command Line

Please leave comments if you have any questions, feedbacks.

Module Development

We recommend:

You also may like these Magento 2 Extensions

One Step Checkout

111 reviews

Layered Navigation

59 reviews

Gift Card

6 reviews

Reward Points

4 reviews


12 reviews

Shop By Brand

16 reviews