Question

I wanted to write unit test case for custom REST API in magento2.

I have already gone through the : http://devdocs.magento.com/guides/v2.0/get-started/web-api-functional-testing.html

I am getting confused as the code example in the link above is written in Magento's namespace. Can anyone tell me how I can write unit test for testing the API's?

Was it helpful?

Solution

Write the tests in your own module namespace in a subdirectory like Test/Api

After you copied phpunit.xml.dist to phpunit.xml, as described in the docs, change the following:

<!-- Test suites definition -->
<testsuites>
    <testsuite name="Magento Web API Functional Tests">
        <directory suffix="Test.php">testsuite</directory>
    </testsuite>
</testsuites>

to

<!-- Test suites definition -->
<testsuites>
    <testsuite name="Your Project Web API Functional Tests">
        <directory suffix="Test.php">../../../app/code/*/*/Test/Api</directory>
    </testsuite>
</testsuites>

../../../app/code/*/*/Test/Api is a relative path to your tests. Adjust it if your directory structure differs.

Now running phpunit within dev/tests/api-functional runs your own tests instead of the core test suite.

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