Skip to content

Testing command-line tools and web apps

How command-line tools and web apps behave at runtime and how to test them, from exit codes and output streams to headless browsers.

Start here

How to test a command-line application

Testing a command-line application means running it the way users and scripts do and checking its output, errors, exit codes, and behavior in pipes.

11 min read

Concepts

  • What are exit codes?

    An exit code is the number a program returns when it finishes, where 0 usually means success and any other value signals an error that scripts can check.

  • What is a headless browser?

    A headless browser is a web browser that runs without a visible window, controlled by code, so tests and agents can load pages and act on them.

  • What is a browser test framework?

    A browser test framework is an open-source library that drives a real browser from test code, so a test can load pages, act on them, and check results.

  • What is Playwright MCP?

    Playwright MCP is a server that lets an AI agent drive a real browser through the Model Context Protocol, using page snapshots instead of screenshots.

How-to guides

  • How to verify a CLI that a coding agent built

    Verifying a CLI that a coding agent built means installing it fresh, running the commands a user would, and checking exit codes, output, and files.

  • How to test a terminal UI (TUI)

    Testing a terminal UI (TUI) means running it in a pseudoterminal, sending keystrokes, and comparing the screen it draws with a reviewed snapshot.

  • How to test shell scripts

    Testing a shell script means running it with controlled input and environment, then checking its output, exit code, and the files it changes.

Comparisons

Common questions

Failures and bugs

  • What is a broken pipe error (SIGPIPE)?

    A broken pipe error happens when a program writes to a pipe or socket whose reader has closed, which sends it SIGPIPE and often ends it with exit code 141.

  • What is a hydration error?

    A hydration error happens when the HTML a server rendered does not match what the browser's JavaScript renders, so the framework warns or re-renders.

Terms in this topic

Browser test framework
A browser test framework is an open-source library that drives a real browser from test code, so a test can load pages, act on them, and check the results.
Command-line interface (CLI)
A command-line interface is a way of using a program that takes typed commands, flags, and input in a terminal or script, and returns output, errors, and an exit code.
Exit code
An exit code is the number that a program returns when it finishes, where 0 usually means success and any other value signals an error that scripts can check.
Headless browser
A headless browser is a web browser that runs without a visible window and is controlled by code, so tests and agents can load pages and act on them.
Hydration error
A hydration error is a web app failure that happens when the HTML a server rendered does not match what the browser's JavaScript renders on load.
Playwright MCP
Playwright MCP is an open-source server that lets an AI agent control a real browser through the Model Context Protocol, using structured page snapshots instead of screenshots.
SIGPIPE
SIGPIPE is the signal that a program receives when it writes to a pipe whose reader has closed. By default it ends the program, and shells report exit code 141.
Standard streams
The standard streams are the three channels that every process gets by default, which are standard input for data in, standard output for results, and standard error for diagnostics.
stderr
stderr is the standard error stream that a program writes errors and diagnostics to, so they stay separate from the results on standard output.
stdout
stdout is the standard output stream that a program writes its normal results to, so another program, a file, or a terminal can read them.
TTY
A TTY is a terminal device that a program can detect, and many programs change their output, color, or prompts when they write to a pipe instead of a TTY.

11 terms from the Learning Center glossary.