Goal: 
Find an issue that needs an automated test created. Write PHP code for the test and submit it to the issue as a patch file or merge request.
Detailed steps: 
  1. Set up prerequisites: Log in, Git, possibly Git Authentication, and Local development site from Common Prerequisites for Contributors. To run certain types of tests locally, you may need to install additional software (see below).
  2. Find an issue that needs an automated test written, in the Drupal core project or a contributed module, theme, or distribution project that you are familiar with. Using the Advanced search page for the project, search for issue status Active or Needs work and (at least in Drupal core) tag Needs tests. You can use this link to search for Drupal core issues that need tests written. Start with a bug report issue if you haven't done this task before (this writeup will concentrate on writing tests for bugs rather than new features).
  3. Read the issue summary and the last few comments, plus the comment where the Needs tests tag was added, and make sure that:
    • You understand the issue
    • You understand what automated tests need to be written
    • No one else has recently commented that they are working on writing the automated tests
    • If there is an existing patch file or merge request on the issue, it doesn't already contain the necessary automated tests.

    If any of these are not true, find another issue to work on.

  4. Verify that you can reproduce the bug or problem described in the issue on your local development site. If not, see the task on issue triage for suggestions on what to do, and/or find another issue.
  5. Your task now is to create an automated PHPUnit test or Nightwatch JavaScript 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. To do this, you'll need to follow the steps in the task writeup for creating a patch or creating a merge request; the rest of the steps in this task writeup are about the details of writing the code for a test.
  6. Determine what type of test you need to write: Unit, Kernel, Functional, FunctionalJavaScript, or Nightwatch.
  7. Check the code base to see if there is an existing test that you can add a method or a few lines to to test the bug. PHPUnit and Nightwatch tests can be found under the following locations:
    • A module's tests/src directory. This could be in any module inside a contributed project, the Drupal core module that bug is related to, or the Drupal core system module.
    • For Drupal core tests, the core/tests directory (for system-level tests).
  8. If there is not an appropriate test to add to, you'll need to create a new test class. Useful information:
  9. After writing your test, run the test locally and verify that it fails without the bug fix patch, and passes with the bug fix patch applied. See the core/tests/README.md file in your local Drupal installation for information on how to run tests of each type; running FunctionalJavaScript and Nightwatch tests may require installing additional software.
  10. Make a patch and interdiff that contains both the bug fix and the test code, or commit to the merge request (see above task links for details).
  11. Make a patch file with just the test in it (without the bug fix code). The name of this patch should end in "TEST-ONLY-FAIL.patch". Do this even if the issue is using merge requests.
  12. Upload the patch(es) to the issue. Add a comment to the issue, explaining your test and the patches, interdiffs, and/or merge request changes you made. Change the issue status to Needs Review. Save the issue status and comment.
  13. The automated tests should now run. Watch the issue and verify after the tests are finished that your test-plus-fix patch or merge request passed all tests, and that the test-only patch failed in the expected way. Add a comment to the issue after the tests run to explain the results (if as expected). If the results are not as expected, update your test until it is working correctly.