Running the tests for Magento to using php bin/magento dev:tests:run
takes a lot of time.
Is there a way to run the tests for a specific module only?
I'm a noob in (unit) testing so have mercy.
Magento 2 use phpunit framework for running test. You can run test per type and module with command:
{phpunit_executable} -c {Magentoroot}/dev/test/{type}/phpunit.xml[.dist] path/to/module/test/dir
For example:
to run unit test for Catalog, you need run command
vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/
to run integration test for Catalog, you need run
vendor/phpunit/phpunit/phpunit -c dev/tests/integration/phpunit.xml.dist dev/tests/integration/testsuite/Magento/Catalog
Currently only unit test moved to modules. Also static and integration integrity test is working with all magento code.
php vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/magento/module-catalog/
kandy's answer seams like the way to go, but in the mean time I found a quick and dirty way to do it.
Copy dev/tests/unit/phpunit.xml.dist
to dev/tests/unit/phpunit.xml
and replace
<directory suffix="Test.php">../../../app/code/*/*/Test/Unit</directory>
with
<directory suffix="Test.php">../../../app/code/[Namespace]/[Module]/Test/Unit</directory>
and comment out the other directory
tags inside the <testsuite>
tag.
When you are done, revert your changes or remove phpunit.xml
.
vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Catalog/Test/Unit/
php vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/magento/module-catalog/
Magento's core codes is moved to vendor/magento path.
phpunit.xml
file and put the path to the module you want to test.
just to add that by using Phpstorm IDE you can define Test configuration for your module and run it separately. Running Tests in PhpStorm
all, unit, integration, integration-all, static, static-all, integrity, legacy, default
. And some general options like-h, -q, ...
that are available for all commands. So nothing special about them