So far for my Magento 2 testing needs, I've been using PHP Unit as (more or less) an acceptance tester — testing results of server and HTML requests made into a system with my module(s) installed. I'd like to be able to create my own integration tests. Do the testing tools that ship with Magento 2 allow third party developers to create their own integration tests that leverage Magento's test framework code? Or will we all be rolling our own bootstrap?
That is
- I am a Magento developer
- I'd like to create an integration test
- I'd my integration test to have a fully bootstrap Magento environment to play in (i.e object manager and/or dependency injection to use)
- I'd like my integration test to extend the
Magento\TestFramework\TestCase\AbstractController
test so I have the same helpers as Magento tests - I'd like to be able to run my tests in isolation from the rest of the test suite (i.e. not have to wait 2 hours to run my 15 seconds of tests)
- I'd like my tests stored separately from Magento's tests
The dev docs site has some starter articles on testing, but they seem oriented at running the tests that ship with Magento and not creating and running your own tests. There's the old sample modules, but they all extend the PHPUnit_Framework_TestCase
class and seem to be unit tests (i.e. testing code that doesn't rely on the Magento framework)
Is there a Magento provided way of doing this?
If not, has anyone rolled their own setup in such a way that the test of the Magento developer community could adopt it as a standard?
Best Answer
This works for us but we haven't yet looked into moving them to a separate location to address 6.)
1.) Place your integration tests under
dev/tests/integration/testsuite/Vendor
2.) copy
dev/tests/integration/phpunit.dist.xml
to
dev/tests/integration/phpunit.xml
and replace
with
3.) run it
../../../vendor/bin/phpunit
or with../../../vendor/bin/phpunit path/to/tests
from the dev/test/integration folderPlease note that the integration tests take longer than 15 seconds, at least on first run as it essentially installs Magento. You can save on subsequent runs if you use
<const name="TESTS_CLEANUP" value="disabled"/>
in your
phpunit.xml