Guide

Testing README code examples

A README is often the first path a reader follows. Test its install and usage examples in a clean environment, check the result and keep the path working through releases.

Published
Updated
November 10, 2026
Reading time
15 min
Facts checked against
Existing DocsAlive documentation and guide coverage (November 7, 2026)
Outlined documentation pages with a lime pulse line running out of the stack
On this pageThe short answerWhy README examples breakMap the reader's pathStart with a clean environmentExecute the usage sequenceCompare output without hiding changesHandle credentials, interaction and external statePut README checks in CIDecide what a failure meansREADME testing checklistWhat this does not replaceFAQ

The short answer

Test a README as the first sequence a reader follows: start in a clean environment, run the documented install command, execute the usage examples in order, and check the results the page promises. Test the version and installation source the reader will actually use. Record prerequisites, skipped paths and any setup supplied by the test, so a passing result does not conceal a missing step.

Run focused checks on pull requests, test a candidate artifact before publication when you need a release gate, and repeat them on a schedule to find dependency and installation drift. For the broader practice, start with how to test documentation code samples.

DocsAlive extracts supported fenced examples and runs or checks them in page order. Its reports classify findings and show skips; credentials are classified rather than used to execute examples, compiled-language examples are not executed yet, and TypeScript support is limited. Review the report alongside the actual coverage rather than treating a pass as proof of the whole README.

Why README examples break

A README often supplies the first install command, a short usage example and a link to deeper documentation. It may be the only page a prospective user reads before deciding whether the project works. That makes even a small break expensive: a renamed package, an import that moved, or an option removed from a command can stop the first successful run.

The README also sits at several boundaries. Repository instructions can describe the current development branch while a package registry serves a release from last month. A command may work for a maintainer because a dependency is already installed or a local configuration file supplies a value. An example can execute successfully but print different output from the result shown on the page.

Consider the promise behind a simple sequence: install a package, import it, call a function, and see a result. Each step depends on the last. A syntax check on the final block will not prove that the install command finds the intended distribution. A test that installs the project from the checkout may pass even when the package published to a registry is incomplete. A successful command can still produce stale output or rely on an undocumented environment variable.

Testing these promises is part of managing documentation drift. The goal is not to run every line indiscriminately. It is to know which reader paths were exercised, which assumptions the test supplied and which claims remain unverified.

Map the reader's path

Read the README from the beginning as a new user would. List the supported platforms, prerequisites, installation alternatives and first useful outcome. Identify which blocks form a sequence and which are alternatives. A Python and a JavaScript tab may illustrate the same task, but executing one does not establish that the other works.

README element Promise to check Common breakage
Prerequisites Required runtime and system tools are named A new minimum runtime is missing
Install command The named package or artifact can be installed Package name, version or registry changes
Import or invocation The installed package exposes the documented entry point Module, command or export is renamed
First example The steps work in the shown order An omitted import or configuration is needed
Expected output The meaningful result matches the explanation Output shape or a default changes
Configuration Placeholders and required values are explained A new required setting is absent
Alternatives Each supported path has an appropriate check Only the primary operating system is exercised
Next step A reader can find the relevant deeper guide A link or versioned path goes stale

Assign an owner to the important paths. Start with the install and first successful use; then add common configuration, supported installation alternatives and error recovery. Inventory examples that cannot be executed unattended rather than leaving them invisible. A small list with owners and explicit gaps is more useful than a large suite whose actual coverage no one understands.

The page may contain badges, generated content, screenshots and prose in addition to code. Execution is one layer of review. Use a link checker for destinations and a person for the explanations, visual presentation and whether the examples answer a real reader question. The free tools guide covers other layers.

Start with a clean environment

Create an environment that resembles the documented starting point. If the page says only that Python is required, begin with the stated supported Python version and an empty environment. Do not inherit the maintainer's project dependencies, shell aliases, credentials or configuration. Install any operating-system tools the README explicitly requires, and record them with the test.

For a Python project, the following illustrates the isolation step; substitute the runtime and commands appropriate to the project:

python -m venv /tmp/readme-check
. /tmp/readme-check/bin/activate
python -m pip --version

The environment alone is not the test. Follow it with the install command from the README and then the usage sequence. If the README asks a reader to clone the repository first, include that step. If it promises installation from a registry, installing a local checkout instead answers a different question. Keep any test harness outside the source tree when local files could accidentally shadow the installed package.

Record the operating system, runtime, package source, package version and network assumptions. Where a project supports several versions, choose a documented matrix and make its limits visible. A Linux check does not prove a Windows command works, and a check on the newest runtime does not establish compatibility with the oldest supported runtime. The right matrix depends on the paths the project promises, not on every combination a runner could create.

Run the install the reader sees

Copy the install command as documented. Verify the distribution name, version constraint, registry or repository URL, and any extras or feature flags. A successful installation should be followed by a check that the intended artifact is the one imported or invoked. An old global executable on the runner can otherwise make a broken install look successful.

A package name and import name do not always match. If the install command uses one name and the example imports another, the test should preserve that distinction rather than rewriting either side. Similarly, a command that depends on a separate system library may install the Python package successfully but fail at first use. The README should state that prerequisite if a reader must provide it.

When the install requires network access, distinguish an unavailable registry from a wrong package name or version. Retain the error and the target source. A retry can help diagnose a transient outage, but repeated retries should not silently turn a recurring installation problem into a pass.

Test checkout, candidate and published versions separately

These checks answer different questions:

Target What a pass establishes What it does not establish
Current checkout The proposed docs work with the tested source and setup The built or published artifact contains the same files
Built candidate The docs work with that artifact before publication The public install path serves that artifact
Published package The tested public path served a working artifact at that time A future release will work or a prior release was blocked

For a release gate, build the candidate, install it in a fresh environment and run the examples before publication. Record the artifact and version. After publication, a separate check of the public install path can detect packaging or registry problems, but it cannot block a release already shipped. The SDK docs release-gate guide goes deeper on testing the built package.

A README in a repository may intentionally describe unreleased behavior. If so, say which version it targets and maintain a way for readers of an earlier release to find matching instructions. Otherwise a test can correctly pass on the default branch while users of the stable package encounter an unavailable method.

Execute the usage sequence

Preserve the order in which readers encounter dependent blocks. An import in the first block can be needed by a call in the next; a shell command can create the file consumed later. Start a new independent example from a clean state when the README presents it as independent. If the page relies on a file, dataset or earlier command, make that relationship clear.

A useful first-use example is complete enough to copy, with imports, a small input and a visible outcome. A fragment can be appropriate when it illustrates one detail, but label it as a fragment and explain the surrounding context. Avoid silently adding missing imports in the test harness: that may make the test pass while leaving the reader with an error.

For example, a README might show an illustrative calculation and result:

values = [2, 4, 6]
mean = sum(values) / len(values)
print(mean)
4.0

An exact output check is reasonable here because the input and result are stable. For a real package, replace the calculation with the documented invocation and use the actual artifact under test. If a later example changes a configuration file or working directory, decide whether that state is part of the documented sequence or a separate path.

Check more than the exit status when the README promises a result. An example can exit successfully while returning an empty list, writing to the wrong directory or using a default different from the page. Assert the meaningful behavior and explain the result a reader should expect. When the example intentionally changes state, inspect the controlled state as well as the process result.

Keep test setup visible

A harness may need to prepare an isolated directory, a small input file or a local fixture. Record what it supplies, and compare that list with the prerequisites on the page. If the harness supplies a configuration value that the reader is never told to set, the README may be incomplete even though the command passes.

Sometimes a fixture stands in for a remote service. That makes an example repeatable and can check how code handles a response, but it does not show that the live service is available or returns the same data. Label the target in the report. Use a separate authorized integration test when the live behavior is part of the promise you need to verify.

A setup command that installs the checkout can also hide a broken documented installation. Test the README install line independently or make that limitation clear. Do not insert a helpful environment variable, secret or executable into a test and then report the page as self-contained.

Compare output without hiding changes

Output can be a contract, an illustration or a partial excerpt. The page should tell readers which. A stable string or a required field can be compared exactly; a generated identifier, timestamp or unordered collection may need a narrower assertion.

Shown output Useful check Review question
Deterministic calculation Compare the exact value Is formatting part of the promise?
Generated identifier Check presence and expected type or form Does the page explain that it varies?
Timestamp Check the relevant field and meaning Is the timezone or format significant?
Unordered results Compare the relevant members Is ordering actually documented?
Error message Check the failure status and meaningful message Does the reader need the exact wording?
Partial output Check the shown properties and label omissions Could an ellipsis be mistaken for literal output?

Normalize only known variable fields. Removing every differing line can hide a renamed field or a missing error. Keep expected and actual evidence so a reviewer can decide whether the documentation, the implementation or the comparison should change. If the README shows a representative response, say which values are examples and which shape or fields the user should rely on.

Output also includes files, exit codes and side effects. A command that prints success but returns a failure status can break a script; a quiet command can succeed. Check the behavior the page describes rather than assuming that text on stdout is the only useful result.

Handle credentials, interaction and external state

Not every README example should run in the same unattended job. A command may require a secret, open a browser, wait for input, start a long-running server or modify a remote resource. Identify these cases and select an appropriate separate check. Do not put real keys in documentation, fixtures or logs.

Case Safer coverage Remaining question
Credential placeholder Check the configuration shape with harmless values Does an authorized live flow work?
Interactive prompt Check an available non-interactive path separately Is the interactive path still understandable?
Long-running process Test a bounded readiness condition and stop it Does the full workflow behave as described?
State-changing command Use an isolated disposable target where appropriate Was cleanup verified?
Remote dependency Use a fixture for local behavior and record its scope Does the deployed dependency agree?
Platform-specific command Run on the relevant platform or record a gap Which supported platforms remain untested?

A timeout is evidence to investigate, not an automatic verdict that the README is wrong. The process may be waiting for a prompt, an external service may be unavailable, or the command may be intended to remain running. Preserve the command and environment with the result. For credentialed behavior, use a separate authorized environment and a narrowly scoped test account when appropriate.

DocsAlive classifies examples needing credentials rather than executing them with real keys, including customer-provided test credentials. Interactive, graphical, destructive and long-running commands need a deliberate separate strategy; a skip or timeout does not establish whether the reader's full path works.

Put README checks in CI

Use different runs for different questions. A pull request check can catch a renamed import before merge. A pre-publication check can test the candidate artifact. A scheduled run can find a dependency or registry change even when the repository has not changed.

When Run Response
Pull request Relevant README paths against the proposed change Investigate likely bugs before merge
Before release Documented sequence against the candidate artifact Block publication when the agreed gate fails
After release Published install path against the released version Investigate packaging or distribution drift
Scheduled First-use paths and selected alternatives Assign failures and monitor skipped runs
Manual A focused reproduction using recorded setup Preserve evidence for the owner

Keep a fast first-use test in the pull request path. Run broader platform and dependency matrices at a cadence that fits the project, and make the delay explicit. Include changes to the package and build configuration as triggers, not only edits to the README: code and packaging changes can break an unchanged page.

For a practical workflow, create a clean environment, install the chosen target, execute the documented sequence and retain the output and version. Make a failing stable assertion visible to the pull request author. Give uncertain network failures and unsupported paths an owner rather than suppressing them. Review the job periodically: a scheduled check that no longer runs gives no evidence of current health.

Use DocsAlive for supported examples

The CLI accepts a local directory or Git URL. Without --execute, it extracts and plans rather than running examples. For a focused local scan, adapt the include pattern to the repository and inspect the selected files:

docsalive scan . --execute --include "README.md" --out out

The pipeline extracts fenced blocks and an output block immediately following a block. It keeps blocks in page order and selects one variant from each tab group. Each page receives a fresh container. Python, JavaScript on Node 20, simple TypeScript, shell and curl or HTTP examples have the coverage described in the framework reference; compiled-language examples are recognized but not executed yet. Other tab variants require separate coverage.

The default environment includes Python 3.12 and Node 20. A project may need a different image or setup. If setup installs the project, record whether it installed the checkout or a candidate artifact and check that it has not hidden an omitted README instruction. The CLI reference describes the available options.

Read report.md and report.json with the findings reference. A pass may represent execution or a syntax check; warnings, failures and skips require context. The report identifies code blocks and reasons, but it cannot prove that an unselected alternative, a live credentialed flow or a missing example works.

Decide what a failure means

A useful triage policy separates the reader-facing problem from an environmental failure without discarding either. Record the page, line, command, tested artifact, runtime, setup, actual output and expected behavior. Give an owner a way to reproduce the result.

Finding First action Possible resolution
Install fails Check the target, package name and network evidence Fix the command or investigate distribution
Import is missing Verify which artifact was installed Fix packaging or update the example
Example needs an undocumented variable Compare harness setup with the page Document the prerequisite or remove the dependency
Stable output changed Compare behavior with the intended release Update docs or investigate a regression
Variable output differs Identify the meaningful invariant Clarify the example and narrow the comparison
Remote service is unavailable Preserve the response and run context Investigate availability and retry deliberately
Block is skipped Read its reason and assign coverage Add a suitable separate test or accept a documented gap
Alternative platform is untested Identify the promised support Add a platform check or state the limitation

A test failure is not always a documentation bug, and a passing check is not always execution. Review status, category and reason together. When a model provider is configured, DocsAlive can draft a small fix and re-run the fixed page, retaining the fix only if it passes. Without a provider, triage is deterministic; fix pull requests open as drafts and are designed not to merge automatically.

README testing checklist

  • [ ] List installation methods, supported versions and first-use paths.
  • [ ] Start in a clean environment with the stated prerequisites.
  • [ ] Run the actual documented install command and record its source.
  • [ ] Verify the installed artifact, import or executable and version.
  • [ ] Run complete blocks in reader order, without hiding missing setup.
  • [ ] Check the meaningful result, exit status and relevant side effects.
  • [ ] Explain placeholders, fragments and variable or omitted output.
  • [ ] Record fixtures, credentials, interaction and platform coverage gaps.
  • [ ] Test the candidate before release if the check is a release gate.
  • [ ] Check the published install path and schedule checks for drift.
  • [ ] Assign owners to failures and have a person review the reader journey.

What this does not replace

A test cannot decide whether the README teaches the right concept, explains a decision clearly or includes the example a new user needs. Ask a person unfamiliar with the project to follow the path, and pair execution with link, Markdown and prose checks. The CLI guide covers command-specific behavior; notebook testing covers executable documents with cells and saved output.

For CI setup, see testing docs in GitHub Actions. For site source formats and execution coverage, see testing code examples in static sites.

See pricing for DocsAlive plans: Team is $299 per month and Growth is $699 per month. To discuss coverage for your documentation, contact us.

FAQ

What should a README test run first?

Start with the documented prerequisites, install command and first useful example in a clean environment. Check the result the page promises and record the version, source and setup used.

Is testing the repository checkout enough?

It checks the proposed source with that setup, but does not prove a built or published package works. Test the candidate artifact before publication for a release gate and check the public install path separately after release.

Should output match exactly?

Compare stable promised values exactly. For variable identifiers, timestamps or ordering, check meaningful stable properties and explain what can vary. Keep normalization narrow.

How should secrets and interactive examples be handled?

Keep real secrets out of the page and logs. Record the untested path and use a separate authorized check where needed. DocsAlive classifies credential-dependent examples rather than executing them with real keys.

Does a passing report cover every README example?

No. A pass can mean execution or a syntax check, and blocks, tab alternatives and unsupported languages may be skipped. Review the coverage and reasons with the report.

For Go-specific example functions and Markdown checks, see testing Go documentation examples. For Java and PHP READMEs, see testing Java documentation examples and testing PHP documentation examples. When README examples need an API key, see testing docs examples that need API keys.

For the install step itself, see testing installation instructions in docs.

Keep reading
Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs Testing: How to Test the Code Samples in Your Docs

Why code examples in documentation break, the ways teams test them (doctest, docs-as-tests, CI runners) and how to run every sample on each release.

Two lenses held over the same documentation page, each bringing a different layer into focusComparison

Vale vs markdownlint: What Each Docs Linter Catches

Vale checks prose style; markdownlint checks Markdown structure. What each catches, sample configs, running both in CI and what neither one tests.

Blueprint of two documentation pages: one with a handwritten test script, one whose code blocks are framed and checkedComparison

Doc Detective vs DocsAlive: Testing the Code in Your Docs

Doc Detective is a free, open-source docs-as-tests framework; DocsAlive is a hosted docs CI for code examples. Features, price, setup and when to use each.

A machine blueprint above a ruled documentation page, with a caliper measuring between themComparison

Promptless Alternative: Promptless vs DocsAlive Compared

Promptless drafts docs updates from what you ship; DocsAlive runs the code examples you've published. Features, pricing, security and when to use each.

A long workbench of outlined testing instruments, each with a small lime light, beside a stack of documentation pagesGuide

Best Free Tools to Test Code Examples in Documentation

Free, open-source tools that run the code examples in your docs: rustdoc, Go examples, doctest, pytest plugins, Sphinx doctest, Doc Detective and byexample.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing SDK Docs Before Every Release: A Release-Gate Guide

Test SDK and client-library docs against the package you ship: build the wheel or npm tarball, install it clean, run every example, and gate the release in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test Quickstarts and Tutorials in Your Docs

Test the onboarding path a new reader follows: run quickstarts in a clean environment, in page order, sort real bugs from credentials and fragments, and wire it into CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test CLI Documentation: Commands, Flags and Output

Test the commands a CLI page promises: install in a clean container, run examples in order, compare flags with --help, check exit codes and output, and run it in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

How to Test API Reference Docs: Requests, Responses and SDKs

Test API reference pages against the contract they publish: methods, parameters, request and response examples, SDK snippets, status codes and OpenAPI samples.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs testing for API-first companies

Keep API quickstarts, SDK snippets and curl examples working across releases.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs testing for CLI and developer-tool vendors

Test developer-tool install paths, package managers and command examples across releases.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Notebooks and Executable Docs: Cells, Kernels and Output

Test notebooks in fresh kernels, check meaningful output and manage dependencies, data and drift in CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Docs in GitHub Actions: Pull Requests and Scheduled Checks

Run documentation example checks in GitHub Actions with practical guidance on schedules, path filters, caching, secrets and reports.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Code Examples in MkDocs, Docusaurus and Sphinx Sites

Find and test documentation examples in Markdown, MDX and reStructuredText, alongside site builds and link checks.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Python Docs Testing: Doctest, Pytest and Markdown

Test Python documentation with doctest, pytest, Markdown example execution and isolated environments.

Outlined documentation pages with a lime pulse line running out of the stackGuide

JavaScript Docs Testing: Node, TypeScript and Modules

Test Node and TypeScript documentation examples across module formats, package versions and type checks.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Go documentation examples

Test Go example functions and Markdown snippets against the intended module versions in clean environments.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Sphinx Docs Testing: doctest, code-block and MyST

Test Sphinx documentation examples: what the doctest and linkcheck builders prove, code-block and literalinclude, MyST fences, and what a Markdown scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

ReadMe Docs Testing: CLI, OpenAPI and Code Examples

Test ReadMe documentation examples: docs-as-code and bi-directional sync, what lint and oas:validate prove, Tabs variants and runnable code.

Outlined documentation pages with a lime pulse line running out of the stackGuide

TypeScript Docs Testing: tsc --noEmit and Runtime

Test TypeScript documentation examples: type-check snippets with tsc --noEmit in a consumer project, then run them, and what each check proves.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docusaurus Docs Testing: Code Blocks, Tabs and MDX

Test Docusaurus documentation examples: builds vs runnable code, code block metadata, Tabs install variants, MDX pages and clean-container runs.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Mintlify Docs Testing: CodeGroup, Tabs and the CLI

Test Mintlify documentation examples: docs.json, MDX pages, CodeGroup and Tabs variants, what mint broken-links and mint validate prove, and clean runs.

Outlined documentation pages with a lime pulse line running out of the stackGuide

MkDocs Docs Testing: Code Examples, Tabs and Snippets

Test MkDocs documentation examples: strict builds, Material tabs, Snippets includes, mkdocstrings pages and clean-container runs.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Installation Instructions: pip, npm and Containers

Test documented install steps in clean environments: pip and extras, venv, npm install vs npm ci, containers and the first import.

Outlined documentation pages with a lime pulse line running out of the stackGuide

AI SDK Docs Testing: LLM Examples, Keys and Drift

Test AI and LLM SDK documentation examples: requests, responses, streaming, tool calls, credentials, model retirements and CI.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing migration guides and changelog examples

Test before and after examples against the right releases and make migration documentation part of the release gate.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Docs Testing Checklist: Code Examples Before Release

A practical pre-release checklist for testing documentation examples, reviewing gaps and verifying published packages.

Outlined documentation pages with a lime pulse line running out of the stackGuide

The Cost of Broken Code Examples in Documentation

Understand how broken documentation examples create friction in developer adoption and support, and how to reduce it.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Rust documentation examples

Test Rust rustdoc examples and cargo documentation tests, and keep native Rust checks because compiled Rust fences are recognized but not executed.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing VitePress documentation examples

Test VitePress Markdown examples separately from the site build, including code groups, includes and what a plain Markdown scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing docs in GitLab CI

Run documentation example checks in GitLab CI jobs, keep site builds separate from execution, and review what a scan covers and skips.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing JSON, TOML and YAML examples in docs

Test JSON, TOML and YAML config examples in documentation: parse, schema and tool checks, honest fence labels, fragments, CI jobs and what a scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing Java documentation examples

Test Java examples in READMEs, SDK docs and Javadoc: the source launcher, javac, JShell scripts, assertions, @snippet files, CI and what a scan covers.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing PHP documentation examples

Test PHP examples in docs: php -l lint, clean-directory runs, assertions with zend.assertions, Composer scratch projects, PHPUnit, CI and scan coverage.

Outlined documentation pages with a lime pulse line running out of the stackGuide

Testing docs examples that need API keys

Test credential-gated docs examples: honest placeholders, offline stubs and fixtures, live sandbox jobs, CI secrets and fork rules, and how a scan classifies them.

A machine blueprint above a ruled documentation page, with a caliper measuring between themGuide

Documentation Drift: How to Detect It Before Users Do

What documentation drift is, why code examples drift first, and practical ways to detect it: ownership, release checks, link and execution tests.

See which of your code samples still run.

Send us a public repository. Our team runs DocsAlive on its docs and emails you the real report within 2 business days. Free, no signup.