Create a PHPUnit Test in Magento 2

In your module create a Test folder and add a unit test file


Add code to your test class


use PHPUnit\Framework\TestCase;

class TestUnitTest extends TestCase
    public function testFirstUnitTest()


  • In command line go to your root of your project and run the test

    ./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/AzCodez/MagentoTraining/Test/Unit/TestUnitTest.php
  • You should get success like below


If this didn't please comment and I will try help you.

Remember to like, post a comment and share this blog if this worked for you.

Happy Coding :)


If this helped you consider buying me a coffee :)