Guide

Testing Swift documentation examples

Run scripts, type-check complete files, keep reader-facing calls in SwiftPM snippets that swift build compiles and assert promised values with Swift Testing.

Published
Updated
November 17, 2026
Reading time
15 min
Facts checked against
the Swift-DocC snippets article, the Swift-DocC plugin, Swift Testing and the official Swift images, with every command run on Swift 6.4.2 on Linux (November 11, 2026)
Outlined documentation pages with a lime pulse line running out of the stack
On this pageThe short answerWhy Swift examples stop workingDecide what each block is meant to beRun scripts and type-check filesPut important examples in Snippets/Embed compiled snippets in DocCAssert behavior with Swift TestingExtract standalone Markdown fences for a basic checkLabel fences and read coverage honestlyRun package checks in CITriage failures before filing a docs bugWhere DocsAlive fitsPasteable checklistThe sources we checkedFAQ

The short answer

Test Swift documentation examples in the toolchain, language mode and platform environment the page promises. Run standalone scripts, type-check suitable complete files, and put important package examples in SwiftPM’s Snippets/ directory so swift build compiles them. Use tests for promised values, mark fragments clearly, and record platform and dependency requirements. A compiler success is useful evidence, but it does not by itself prove that a reader can install the package or obtain the stated result.

Run the checks on documentation and API changes, before releases, and periodically for dependency drift. Swift 6.4.2 was released on October 29, 2026; the examples here use Swift 6.4.2 on Linux unless a platform is identified. State the toolchain and platform used for your own docs. See how to test documentation code for the wider workflow.

DocsAlive recognizes swift fences but skips them as not executable today. It can check supported blocks elsewhere on the page and classify findings, while your Swift build and tests supply the Swift-specific evidence.

Why Swift examples stop working

A Swift example can drift when an API changes its argument labels. A call that once used one label may no longer match the function a reader installs, even if the function name still looks familiar. APIs can also be removed, moved to another module or made unavailable on a target platform. A missing import can leave a reader with an error even though the author’s project already imports the required module.

Swift language mode matters as well. Swift 6 language-mode and concurrency checks can expose code that compiled under a different configuration. A check against a toolchain alone should therefore record the language mode and relevant build settings, rather than assuming every project using that toolchain receives identical diagnostics.

Platform assumptions are especially important for Swift packages. A README may show a UI example using UIKit, while a Linux CI runner has no UIKit. That failure can be a runner mismatch rather than an API defect. State that an example requires an Apple platform, test it on a suitable macOS runner, and keep platform-neutral package checks on Linux where appropriate.

Package setup can drift independently of the source. A wrong package URL, version requirement or product name can stop a reader before the example compiles. A local checkout build does not prove that the URL and version in a page lead to the same artifact. Test the install path in a clean consumer project as well as compiling the package’s own source.

DocC catalogs and SwiftPM package documentation often mix complete snippets with fragments and fenced listings. A short fragment may be useful inside a larger explanation, but a reader needs to know where it belongs. A listing presented as a complete script should include its imports and declarations, while a package snippet should declare the module it imports and rely only on the documented package context.

Decide what each block is meant to be

Choose the test after identifying the reader’s intended starting point. A swift fence can hold several different kinds of content.

Block Reader’s context Appropriate check
Script A file run directly with the Swift interpreter Run swift file.swift and check its result
Package snippet A file using a package target or a direct dependency Compile it through swift build; run it when behavior matters
Fragment Part of a larger scope or sequence Mark it and test the surrounding program
Package.swift A package manifest describing targets and dependencies Build a representative package with that manifest
DocC fenced listing Source displayed in documentation markup Add a separate check; the listing itself is not compiled
Output listing A result shown to a reader Compare it with a controlled run if the page promises it

A package snippet and a script may both contain top-level statements, but they do not have the same dependency context. A script that uses only the standard library may run directly. A snippet importing a package target needs a build that supplies that module. Similarly, a Package.swift file should be assessed as a manifest in a package, not merely as an arbitrary source file.

The fictional Acme SDK, module AcmeSDK and variable ACME_API_KEY are placeholders in this guide. They are not instructions to install or call a real service. In an actual SDK guide, use the real package URL, version and product names, and state any credential prerequisite without putting a real secret in the documentation.

Run scripts and type-check files

Save this complete standard-library script as hello.swift:

let name = "Ada"
print("Hello, \(name)!")

Run it:

swift hello.swift

It prints Hello, Ada!. This verifies that the script executes under the selected Swift environment. For a page that promises a specific output, compare the result in a separate test or review; a zero exit status alone does not establish that the displayed result is accurate.

For a fast check that does not execute the file, use:

swiftc -typecheck hello.swift

A type check can catch a missing name, an incorrect argument label or an incompatible type in a complete file. It does not exercise runtime behavior, verify output or prove that an external service is reachable. It also needs the appropriate module search paths and dependencies for code that imports a package.

For example, the following file is intentionally broken because a string is assigned to an integer:

let count: Int = "three"

Saving it as broken.swift and running swiftc -typecheck broken.swift fails with a diagnostic containing cannot convert value of type 'String' to specified type 'Int'. Keep deliberately broken examples clearly labeled in documentation and exclude them from a harness intended for working examples.

Check the environment as part of the promise

Record the Swift version, operating system, language mode and package versions alongside a result. For a package guide, also record whether the test used a checkout or the artifact a reader obtains from the published package URL.

Use a clean consumer project to follow the documented dependency instructions. If the test adds a dependency, import or build setting that the page does not mention, make that addition visible in the test record. A passing sample can otherwise conceal an instruction that a new reader still needs.

For code requiring UIKit or another Apple-platform-only framework, use a macOS runner with the required SDK and say so on the page. A Linux type check cannot establish whether that example works on its intended platform. Conversely, a macOS-only test does not establish Linux support for the rest of the package.

Put important examples in Snippets/

SwiftPM builds top-level files in a package’s Snippets/ directory as individual snippets. Each snippet is its own unit: it cannot rely on declarations from another snippet file. It can import the package’s targets and products of direct dependencies. This makes a snippet a useful home for a complete example that should remain tied to the package build.

Create a directory with this layout:

Greeter/
  Package.swift
  Sources/
    Greeter/
      Greeter.swift
  Snippets/
    greet-someone.swift

Save this manifest as Greeter/Package.swift:

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "Greeter",
    products: [
        .library(name: "Greeter", targets: ["Greeter"])
    ],
    targets: [
        .target(name: "Greeter")
    ]
)

Save the public function as Greeter/Sources/Greeter/Greeter.swift:

public func greeting(for name: String) -> String {
    "Hello, \(name)!"
}

Save the complete snippet as Greeter/Snippets/greet-someone.swift:

import Greeter

print(greeting(for: "Ada"))

From the Greeter directory, build and run it:

swift build
swift run greet-someone

The run prints Hello, Ada!. The build compiles the snippet; the run also exercises its behavior. If the package has several files in Snippets/, a broken one can fail the build even if a different snippet is the one a reviewer intended to inspect.

Now consider this intentionally broken replacement for the snippet:

import Greeter

print(greeting(name: "Ada"))

The function’s argument label is for, not name. With this replacement in Snippets/greet-someone.swift, swift build fails with:

incorrect argument label in call (have 'name:', expected 'for:')

Restore the working snippet after the demonstration. This is precisely the kind of API drift a compiled sample can expose: the documentation file and the public declaration must agree at build time.

Embed compiled snippets in DocC

DocC can embed a snippet from the package rather than duplicating its source in a documentation page. For the preceding file, a DocC markup page can use:

@Snippet(path: "greet-someone")

The path form shown here follows current DocC guidance; before Swift-DocC 6.2.1, the path included the package and Snippets/ components. Check the version used by your documentation build when maintaining older packages.

A snippet can contain setup that the compiler needs but the rendered explanation should not emphasize. Use // snippet.hide and // snippet.show to control which lines DocC displays. Slices can select a named portion with // snippet.<id> and // snippet.end, then embed it with an @Snippet directive using path and slice. The whole source file still needs to compile, so hidden setup is part of the test even when a reader does not see it.

That creates a review responsibility: do not hide an import or setup step that the reader needs to reproduce the example unless the surrounding page supplies it. Hidden code can make a rendered listing look self-contained when it is not. Explain the prerequisites and inspect the rendered page as well as the build.

Fenced code listings written directly in DocC markup are not compiled by DocC. Prefer compiled snippets for examples that must keep working, and use direct listings for intentional fragments or illustrative material with an appropriate separate check. The DocC snippet guide documents embedding, visibility and slices.

The Swift-DocC plugin provides a SwiftPM workflow for documentation generation. Its dependency is available from version 1.1.0; follow its setup instructions for the package and toolchain in use. With the plugin configured, its documented preview command has this form:

swift package --disable-sandbox preview-documentation --target YourTarget

Replace YourTarget with the actual target. Previewing is useful for checking presentation and links, while swift build and tests provide separate evidence about compiled snippets and behavior.

Assert behavior with Swift Testing

Compilation catches the broken argument label, but it does not prove that greeting(for:) returns the value shown in the page. Add a test target to the Greeter manifest when using the following test:

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "Greeter",
    products: [
        .library(name: "Greeter", targets: ["Greeter"])
    ],
    targets: [
        .target(name: "Greeter"),
        .testTarget(name: "GreeterTests", dependencies: ["Greeter"])
    ]
)

Save this as Greeter/Tests/GreeterTests/GreeterTests.swift:

import Testing
import Greeter

@Test func greetingForAda() {
    #expect(greeting(for: "Ada") == "Hello, Ada!")
}

From the package directory, run:

swift test

This test checks the stable return value that the documentation promises. It is separate from the snippet’s build and run: the snippet demonstrates the reader-facing call, while the test makes the expected value an assertion. Keep them aligned when the API or wording changes. The Swift Testing project and Testing reference describe @Test and expectations.

For output containing timestamps, generated identifiers or ordering that is not guaranteed, assert the stable property that matters instead of copying a volatile transcript. If exact output is part of the contract, use a controlled environment and check the exact output there.

Extract standalone Markdown fences for a basic check

The following Python 3 script finds simple swift fences in Markdown, writes each selected block to a temporary .swift file and runs swiftc -typecheck. It skips a block when its first line is // fragment.

Save it as check_swift_fences.py:

import re
import subprocess
import sys
import tempfile
from pathlib import Path

FENCE = re.compile(
    r"^```swift[ \t]*\r?\n(.*?)^```[ \t]*$",
    re.MULTILINE | re.DOTALL,
)


def main() -> int:
    if len(sys.argv) < 2:
        print("Usage: python3 check_swift_fences.py FILE.md [FILE.md ...]")
        return 2

    passed = failed = skipped = 0

    with tempfile.TemporaryDirectory() as directory:
        root = Path(directory)
        number = 0

        for name in sys.argv[1:]:
            path = Path(name)
            try:
                markdown = path.read_text(encoding="utf-8")
            except (OSError, UnicodeError) as error:
                print(f"Cannot read {path}: {error}")
                failed += 1
                continue

            for match in FENCE.finditer(markdown):
                number += 1
                code = match.group(1)
                line = markdown.count("\n", 0, match.start()) + 1
                location = f"{path}:{line}"

                if code.splitlines() and code.splitlines()[0].strip() == "// fragment":
                    print(f"SKIP {location}: fragment")
                    skipped += 1
                    continue

                source = root / f"block_{number}.swift"
                source.write_text(code, encoding="utf-8")
                try:
                    result = subprocess.run(
                        ["swiftc", "-typecheck", str(source)],
                        text=True,
                        capture_output=True,
                        check=False,
                    )
                except OSError as error:
                    print(f"FAIL {location}: cannot start swiftc: {error}")
                    failed += 1
                    continue

                if result.returncode == 0:
                    print(f"PASS {location}")
                    passed += 1
                else:
                    print(f"FAIL {location}")
                    print(result.stderr.strip())
                    failed += 1

    print(f"Summary: {passed} passed, {failed} failed, {skipped} skipped")
    return 1 if failed else 0


if __name__ == "__main__":
    raise SystemExit(main())

Run it with the compiler on PATH:

python3 check_swift_fences.py README.md

This script is intentionally narrow. It handles simple triple-backtick fences at the beginning of a line, not every Markdown construction, nested fence or tabbed format. It treats blocks independently, does not build a package or install dependencies, and does not run code or compare output. A package import may need module paths that this script does not provide; an Apple-platform-only import cannot be checked on Linux.

A // fragment marker prevents an isolated check from misrepresenting a partial listing as a complete file. It does not verify the fragment. Put consequential fragments in a compiled test or snippet with their surrounding context, and check that the page gives a reader enough information to use them.

Label fences and read coverage honestly

Use swift for Swift fences. In DocsAlive today, swift is recognized and skipped with the reason not executable (swift) and category not-executable. Supported blocks elsewhere on the page can still be checked.

The label swift-repl is unmapped. In the current engine, it can appear as a pass even though nothing was parsed or run. Treat that result as unchecked. A green status alone is not evidence that a Swift compiler accepted the listing; inspect the label, status and reason, and use your Swift checks for coverage.

Run package checks in CI

The following GitHub Actions outline uses the Swift 6.4.2 Bookworm container, checks out the repository and runs the package build and tests. It assumes Package.swift is at the repository root and the package is compatible with Linux.

name: Swift documentation

on:
  pull_request:
  push:

jobs:
  swift-docs:
    runs-on: ubuntu-latest
    container:
      image: swift:6.4.2-bookworm
    steps:
      - uses: actions/checkout@v7
      - name: Build package and snippets
        run: swift build
      - name: Run tests
        run: swift test

The build checks package snippets in Snippets/; the test command checks the project’s tests. Neither automatically checks arbitrary Swift fences in a README or DocC page. Add the fence script for the standalone listings it supports, and add consumer-project checks for the documented package URL and version.

Use a macOS runner and the appropriate Apple SDK for examples that import UIKit or other Apple-platform-only frameworks. State that requirement on the page and in the test record. Keep Linux and macOS results distinct so a platform mismatch does not hide either a real portability issue or a valid platform-specific example.

Run the relevant suite when a pull request changes the API or docs, against a release candidate before shipping, and on a schedule when external dependencies can change. After publication, a clean consumer check against the published package answers whether the reader’s install path works. A post-release check supplies evidence after the fact; it cannot serve as a gate for a release that has already shipped.

Triage failures before filing a docs bug

Keep the page, line, command, toolchain, platform and dependency versions with each finding. A diagnostic identifies the immediate failure; the surrounding documentation determines whether it is a defect in the page, a missing prerequisite or a mismatch in the test environment.

Finding What to investigate Likely action
Incorrect argument label Whether the example targets the installed API version Update the call or the documented version
Missing module Whether the page states the import and package dependency Add the missing instruction or correct the test setup
UIKit missing on Linux Whether the example is intended for an Apple platform Test on macOS and state the platform requirement
Swift 6 concurrency diagnostic The language mode and settings promised by the page Reproduce under the supported configuration and update the code or guidance
Fragment fails independently Whether the page supplies its enclosing context Test the complete context and label the fragment
Package URL or version fails Whether the published dependency instructions are correct Verify the real URL and release in a clean consumer project
Output differs after a successful run Whether the result is a stable promise or representative output Reproduce and update the test or the page
Credential or fixture missing Whether a prerequisite is documented and safe to supply in a separate test Record the gap and review the instructions
Timeout or network error Whether the service or network was available Retry or investigate before assigning a documentation cause

A fictional placeholder failure is not evidence that an actual SDK is unavailable. Likewise, a test that silently provides a missing import can make a page look healthier than it is for a reader. Preserve those distinctions in the report and in the fix.

Where DocsAlive fits

DocsAlive extracts fenced blocks with their page and line, plans supported checks and reports results with categories and reasons. It keeps supported examples in page order and uses a fresh container for each page. Its triage helps distinguish likely documentation bugs from missing context, credentials, fixtures and runner limitations. See framework support and findings.

Swift execution is not available in the product today, so pair its report with swift build, swift test and any standalone checks your pages need. A recognized swift block is a skip, not a successful type check. A scan without --execute only extracts and plans; enabling execution does not make Swift blocks executable.

Printed output is compared only for Python pycon or python-repl sessions. A separate output block is recognized and skipped, and its contents are not compared. Use Swift tests or another explicit check for the values and output your Swift documentation promises.

Pasteable checklist

Copy this into a pull request or release checklist:

  • [ ] State the tested Swift version, language mode and platform.
  • [ ] Identify scripts, package snippets, fragments and manifests.
  • [ ] Label Swift fences swift and mark intentional fragments.
  • [ ] Run complete scripts that promise executable behavior.
  • [ ] Type-check suitable standalone files with their required imports.
  • [ ] Put important package examples in Snippets/ and run swift build.
  • [ ] Check each snippet independently; do not rely on another snippet’s declarations.
  • [ ] Use tests to assert stable values promised by the page.
  • [ ] Review hidden snippet lines against the rendered prerequisites.
  • [ ] Verify package URLs, versions and products in a clean consumer project.
  • [ ] Test Apple-platform-only examples on macOS with the required SDK.
  • [ ] Record skipped blocks, credentials, fixtures and platform limitations.
  • [ ] Check the release candidate and, when practical, the published package.
  • [ ] Review diagnostics in context before labeling them documentation bugs.

The sources we checked

These sources were read on November 11, 2026.

Source What it covers
Swift installation Toolchains and the Swift 6.4.2 release
Swift-DocC documentation Documentation catalogs and DocC
Adding code snippets to content Snippet files, embedding, hidden lines and slices
Swift-DocC plugin SwiftPM documentation workflow and preview
Swift Testing and Testing reference Tests and expectations
Official Swift container images Swift container tags for CI
actions/checkout Repository checkout in CI
Findings Product reporting and triage context

FAQ

Does swiftc -typecheck run a Swift example?

No. It checks the file without executing it. Run scripts or package snippets separately, and use tests when the documentation promises a particular value or behavior.

Does DocC compile fenced code listings?

No. A fence written directly in DocC markup is displayed as a listing but is not compiled. Put examples that must keep working in package snippets or provide another explicit check.

What does swift build check in Snippets?

It compiles each file in the package's top-level Snippets directory as its own snippet unit. A snippet cannot use declarations from another snippet file, so include its required context and imports.

Why did a UIKit example fail on Linux?

UIKit is an Apple-platform framework and is not available in a Linux Swift environment. Test that example on a suitable macOS runner and state the platform requirement on the page.

Does a Swift pass in DocsAlive mean the code was checked?

No. A swift fence is recognized and skipped as not executable. The unmapped swift-repl label can appear as a pass without being checked, so use swift and rely on separate Swift tooling.

How can a team catch changed argument labels?

Compile examples against the intended package version, preferably through package snippets for reader-facing calls. A clean consumer build also checks whether the documented dependency setup reaches that version.

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 README Code Examples: Install, Usage and CI

Keep README install commands and usage examples working with clean environments, output checks and CI.

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 C# documentation examples

Test C# examples in docs: .NET 10 file-based apps, dotnet build with warnings as errors, test projects, XML doc comments, CI and scan coverage.

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

Testing Ruby documentation examples

Test Ruby examples in docs: ruby -c syntax checks, clean-directory runs, bundler/inline, minitest assertions, YARD examples, CI and scan coverage.

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

Testing Kotlin documentation examples

Test Kotlin examples in docs: kotlinc runnable JARs and scripts, -Werror, KDoc @sample in compiled source, kotlinx-knit, fence labels, CI and scan coverage.

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

Testing curl and HTTP examples in API docs

Test curl examples in API docs: --fail-with-body, status and JSON checks against a local stub, http fences, credentials and what a docs scan checks.

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

Testing Astro Starlight documentation examples

Test code examples in Astro Starlight docs: src/content/docs inventory, Tabs and Expressive Code, Markdoc pages, a Node check script, CI and scan coverage.

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

Testing Nextra documentation examples

Test code examples in Nextra docs: content/ and app/ sources, fence metadata, Tabs and npm2yarn, a Node check script, CI and an honest scan limitation.

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

Docs testing for open-source projects

Test the code examples in open-source docs and READMEs: pull requests from forks, release and scheduled checks, contributor guidelines, triage and the Open source plan.

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

Docs testing for technical writers and docs teams

How technical writers and docs teams test the code examples they publish: docs-as-code checks, style-guide rules, reading a report, routing findings to engineers.

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

Docs testing for DevRel teams

How developer advocates test quickstarts, tutorials, workshops and sample READMEs: an inventory, a launch and release cadence, reading a report, and honest reporting.

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

Testing Hugo documentation examples

Test the code examples in Hugo docs: fences with brace options, the highlight shortcode, Docsy tabs, drafts and theme example sites, scan scope and CI.

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

Testing GitBook documentation examples

Test the code examples in GitBook docs synced to Git: the space root, code tags, tabs, reusable includes, invisible characters, scan scope and CI.

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

Testing SQL examples in documentation

Test SQL examples in docs: run fences in page order on a fresh database, assert results, handle dialects, SQLite STRICT typing, psql ON_ERROR_STOP and CI.

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

Testing mdBook documentation examples

Test the code in an mdBook: what mdbook test covers, rust attributes, hidden lines, include directives, untagged output fences and a scan-ready copy for CI.

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

Testing Docsify documentation examples

Test the code examples in Docsify docs: embedded code files and fragments, docsify-tabs tab sets, Prism grammars, scan scope and a CI check.

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

Testing Jekyll documentation examples

Test the code examples in Jekyll docs: include tags, site variables, highlight tags, posts and _site copies, a scan-ready copy and Ruby hooks.

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

Testing Antora and AsciiDoc documentation examples

Test the code examples in Antora docs: example includes, tagged regions, attributes, failing the build on missing includes and a Markdown copy to scan.

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

Testing Fumadocs documentation examples

Test the code examples in Fumadocs docs: npm fences and package-manager tabs, tab groups, the Tabs component, includes, pycon highlighting and a scan-ready copy.

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

Testing versioned Docusaurus docs

Test every Docusaurus version readers can reach: versioned_docs copies, versions.json, partials, tabs, per-version scans and old-version triage.

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

Testing Read the Docs documentation examples

Test the code examples on a Read the Docs site: .readthedocs.yaml build jobs, a pycon gate, latest and stable versions, Sphinx, MyST and .rst coverage.

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

Testing Eleventy documentation examples

Test the code examples in Eleventy docs: Liquid pre-processing, global data, include tags, ignored drafts, raw tags and a rendered copy to scan.

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

Testing Zola documentation examples

Test the code examples in Zola docs: Tera content templating, raw tags, config values, hide_lines, drafts, blog posts and a scan-ready copy.

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

Testing Quarto documentation examples

Test the code examples in Quarto docs: executable cells, display-only fences, freeze and _freeze, a CI profile, cell options and a copy to scan.

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

Testing Hexo documentation examples

Test the code examples in Hexo docs: posts, drafts, scaffolds, codeblock and include_code tags, a build check and a scan-ready copy.

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

Testing pdoc documentation examples

Test the code examples in pdoc docs: doctest for >>> sessions, fenced docstring examples, the README, private items and a copy to scan.

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

Testing Doxygen documentation examples

Test the code examples in Doxygen docs: compiled example files, snippets, Markdown pages, WARN_AS_ERROR and what a scan can and cannot check.

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

Testing TypeDoc documentation examples

Test the code examples in TypeDoc docs: example tags, includeCode regions, project documents, a compiler check of extracted examples and a scan.

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

Testing JSDoc documentation examples

Test the code examples in JSDoc docs: example tags, captions, source patterns, tutorials, a doclet export and a scan-ready copy with assertions.

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

Testing docs examples with pre-commit hooks

Check docs code examples with pre-commit: local hooks, files filters, always_run, pass_filenames, SKIP and --no-verify, and what to leave for CI.

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

Testing documentation examples with Deno

Run docs code examples with deno test --doc: JSDoc and Markdown examples, imports, hashbang permissions, ignored blocks and deno check --doc-only.

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

Testing documentation examples with Sybil

Test Python docs examples with Sybil and pytest: Markdown parsers, invisible setup, skips, clear-namespace, docstrings and pycon fences a scan can read.

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

Testing Markdoc documentation examples

Test the code examples in Markdoc docs: variables in fences, partials, if/else, custom tabs, validate in CI and a scan-ready copy from transform.

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

Testing Markdown examples with phmdoctest

Test Python examples in README and Markdown files with phmdoctest: sessions, output blocks, directives, --report, generated pytest files and pycon fences.

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

Testing Markdown code blocks with pytest-markdown-docs

Run Markdown python fences as pytest tests with pytest-markdown-docs: globals hook, fixtures, continuation, notest, retry and pinning the released version.

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

Testing command line docs with prysk and Cram

Test CLI docs with prysk and Cram: .t transcripts, exit statuses, (re) and (glob) matches, and generating tests from the console blocks in your Markdown.

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

Testing Python docstring examples with xdoctest

Run docstring examples with xdoctest: the pytest plugin, google and freeform parsing, permissive output matching, directives, and what it does not check.

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

Testing multi-language docs examples with byexample

Test docs examples with byexample: prompt-based language detection, the -l selection, +pass, +skip and timeouts, capture tags, and hidden setup in comments.

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

Testing Markdown code blocks with mktestdocs

Run Markdown code blocks under pytest with mktestdocs: exact fence labels, memory=True for shared state, bash blocks, custom executors and docstring checks.

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

Testing README code blocks with pytest-codeblocks

Run README and Markdown code blocks with pytest-codeblocks: exact python, sh and bash labels, cont, skip and xfail markers, expected output, and gaps.

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

Testing Markdown code examples in any language with txm

Test annotated Markdown examples with txm: program, in, out, err, check and exit annotations, TAP output, exact matching, and blocks it never runs.

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

Testing Sphinx docs examples with sphinx.ext.doctest

Run Sphinx doctest, testcode and testoutput directives in reStructuredText or MyST pages: groups, hidden setup, global setup and what is never run.

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.