Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

just to add that by using Phpstorm IDE you can define Test configuration for your module and run it separately. Running Tests in PhpStorm

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top