[Policy] Mock external APIs/resources instead of depending on them directly in tests

Created on 27 October 2022, over 2 years ago
Updated 28 May 2025, about 2 months ago

Problem/Motivation

Tests that depend on external resources or APIs introduce fragility to the testing system. Tests should be consistent and repeatable, and if an external resource has an outage of some kind, we can see false negative or apparently random failures in tests.

For example, any automated tests that depend on YouTube (like: MediaStandardProfileTest::testMediaSources) will necessarily fail if there are ever outage(or even throttling issues) on the YouTube side, even if the test itself is still valid.

Proposed resolution

Wherever possible, we should mock external resource requests or APIs, rather than depending on the live services.

{Add link to doc page and add proposed text}

Remaining tasks

  • identity documentation to update
  • Identify tests dependent on external resources.
  • Update them with mocks.

This is likely to be a slow/longer term effort rather than something that takes immediate priority - but wanted to raise it as an improved best practice for testing. (And align it with Drupal.org testing policy β†’ ).

🌱 Plan
Status

Active

Version

11.0 πŸ”₯

Component

simpletest.module

Created by

πŸ‡ΊπŸ‡ΈUnited States hestenet Portland, OR πŸ‡ΊπŸ‡Έ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024