Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.

You might want to look at the current version, PrestaShop 8. Read the updated version of the documentation

Learn how to upgrade to the latest version.

How to create your own unit tests or add tests to PrestaShop

Unit tests are great if you want to validate the behavior of a single unit of code. By “unit of code” we usually mean a class although it could also be a script.

Creating a Unit test

Everything is explained in the PHPUnit 5.7 documentation.

For unit tests, we strongly encourage you to base your test on the PHPUnit’s TestCase class only.

For instance:

<?php
namespace Tests\Unit\Foo;

use PHPUnit\Framework\TestCase;

class BarTest extends TestCase
{
    /* ... */
}

Unit tests should be located into tests/Unit folder and follow the same path as the tested class: if a class is located into src/Core/Foo/Baz, the unit test should be into tests/Unit/Core/Foo/Baz folder.