Last updated 6 August 2017.

On this page:

To get help completing this task, see the Getting help completing your task page.


Create a patch (software fix) for an automated test to detect a Drupal core bug.

Skills needed

PHP programming skills

Detailed steps

  1. If you don't have a Drupal site to test on, set up a local server. You probably do not want to use a live, production web site for this task.
  2. Install Git on your computer, if it is not already installed. See the installing git page for more information.
  3. Find issues for Drupal core.
  4. Use the advanced search to find an issue tagged with Needs tests.
  5. Make sure you can reproduce the bug on your test site. (If the steps to reproduce the issue are unclear, you can document them or add a comment asking for clarification. If you cannot figure out how to reproduce the bug, choose a different issue.)
  6. Your task now is to create an automated test that follows the steps to reproduce the issue and asserts the expected result. The test should fail when the bug is present and pass once the bug is fixed.
  7. Determine which file should contain the automated test.
    • If the bug is related to a specific core module, the test should be added to:
      • for Drupal 7.x: modules/modulename/modulename.test.
      • for Drupal 8.x: core/modules/modulename/src/Tests/.
      • for Drupal 8.x: read more about phpunit tests.
    • If the bug is related to a core subsystem (such as the menu system), look for an appropriate file in the appropriate directory.
      • for Drupal 7.x: modules/simpletest/tests/
      • for Drupal 8.x: core/modules/system/src/Tests/
  8. Look at the different test case classes in that file and determine if one is a good fit for your test.
    • In Drupal 7, the test should extend DrupalWebTestCase. In Drupal 8, the test should extend Drupal\simpletest\WebTestBase. (Note that many modules have a base helper test class; if so, the test should probably extend that class instead.)
    • Consider the class's name, description, and setUp() method. If there is no class that is a good fit, add a new class for your test at the end of the file. (For more information, see the SimpleTest documentation.)
  9. Add a test method to the class for your automated test. (In some cases, you may be able to extend an existing test method.)
  10. Clear your site cache and run your test to verify that it reproduces the bug (failing the expected assertions when the bug is unpatched).
  11. Create a patch that contains your test code.
  12. If there is already a patch to fix the bug, apply that patch to your test site along with your automated test, clear the cache, and run the test again. The test should now pass. Create a second patch that contains your test code together with the fix.
  13. Create a new comment on the issue and upload your patch as an attachment. If you also created a patch containing a fix for the bug, upload the test-only patch as the first attachment and the combined test & fix patch as the second. If you are updating a previously uploaded patch, you should also upload an interdiff from the last patch to your new patch. Set the issue status to "Needs Review" so that the patches are automatically tested by the testbots. This makes it much easier for reviewers to see the problem exposed by the test-only patch, the proposed changes to fix the problem, and any new material added since the last patch. For a good example, see


Background and reference information

Next steps: moving beyond this task

comment_attachments_tests.png12.02 KB