1

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.