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.
-> https://webkul.com/blog/phpunit-basic-tutorial/
-> https://webkul.com/blog/writing-tests-for-phpunit/
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
OR
php bin/magento dev:tests:run
NOTE : But the above commands takes too much time.
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.
Be the first to comment.