Creating unit tests

This chapter assumes that we have PHPUnit configured and available on the command line. If this is not the case, PHPUnit can be installed using instructions from the https://phpunit.de/ website.

To build and run tests using the PHPUnit testing framework, we need to define test locations and other configuration options via an XML file. Magento defines this XML configuration file under dev/tests/unit/phpunit.xml.dist. Let's make a copy of that file under dev/tests/unit/phpunit-foggyline-helpdesk.xml, with adjustments as follows:

<?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1 /phpunit.xsd" colors="true" bootstrap="./framework/bootstrap.php" ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.