---
title: "Adding a PHPUnit test to the Drupal Auto DevOps pipeline"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to integrate PHPUnit tests into your Drupal Auto DevOps pipeline. Follow our step-by-step guide to set up, configure, and run automated tests for your custom modules, enhancing code quality and reliability."
image:
type: "page"
url: "/acquia-cloud-platform/add-ons/code-studio/adding-phpunit-test-drupal-auto-devops-pipeline"
id: "ce8e29bd-ff28-4165-a86b-cefc41776898"
---

Table of contents will be added

Prerequisites
-------------

Before adding a PHPUnit test to your Code Studio pipeline, you must:

1.  Understand how to implement PHPUnit tests.
2.  Include `drupal/core-dev` and `phpunit/phpunit` in the `composer.json` file of your project.
3.  Place the `phpunit.xml.dist` file in the root directory of your project.
4.  Ensure that a custom module exists in your codebase.

Adding a PHPUnit test to your custom module
-------------------------------------------

1.  In your custom module, create a directory for `tests/src/Functional/`.
    
    For example, `docroot/modules/custom/my_module/tests/src/Functional`.
    
2.  Add a PHPUnit test file.
    
    For example, `ExampleTest.php`.
    
    ![ExampleTest.php file exists inside the Functional directory that is present in
    docroot/modules/custom/my_module/tests/src](https://acquia.widen.net/content/okof8iinoo/jpeg/code-studio_phpunit-test-file.jpeg?position=c&color=ffffffff&quality=80&u=0b06mk)
    
3.  Add your PHPUnit test cases to the test file.

Updating the PHPUnit configuration file
---------------------------------------

In the `phpunit.xml.dist` file, ensure that the path to your custom modules directory exists under a test suite. For example, if your module exists in the `docroot/modules/custom/` directory, ensure that the `phpunit.xml.dist` file contains the following:

    <?xml version="1.0"?>
    <!-- phpunit.xml.dist -->
    <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
       <coverage processUncoveredFiles="true">
          <include>
             <directory suffix=".php">src</directory>
          </include>
          <report>
             <clover outputFile="build/logs/clover.xml"/>
          </report>
       </coverage>
       <testsuites>
          <testsuite name="Custom modules">
             <directory>docroot/modules/custom/</directory>
          </testsuite>
       </testsuites>
       <logging/>
    </phpunit>

Adding project variables
------------------------

The following variables must be set in your project:

*   `ACQUIA_TASKS_SETUP_DRUPAL` must be set to `true`. For more information, see [Adding environment variables](/acquia-cloud-platform/add-ons/code-studio/customizing-code-studio/default-code-studio-pipeline/environment-variables#section-adding-environment-variables).
*   If `ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT` exists, it must be set to `true`.
*   If `ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY` exists, it must be set to `install`.
*   If `ACQUIA_TASKS_PHPUNIT` exists, it must be set to `true`.
*   If `ACQUIA_JOBS_TEST_DRUPAL` exists, it must be set to `true`.