tmux-tui-testing is a Go testing framework designed for automating tests within a
tmux
session. It enables automated execution of test specifications by simulating user interactions with terminal programs inside tmux
.
tmux-tui-testing
is designed to address the challenges of testing terminal-based applications, particularly CLIs with complex interactions.
Traditional testing methods often fall short when it comes to simulating real user interactions in a terminal environment.
With this framework, you can perform end-to-end tests that simulate real user behavior inside a tmux session, such as executing commands, handling interactive prompts, or verifying terminal output.
This is especially useful for testing CLIs that involve multiple steps, a real TTY or depend on terminal-specific behaviors.
- Automates testing of terminal-based applications.
- Uses
tmux
to create, manage, and destroy test sessions. - Supports test specifications defined in
.ttt
files. - Provides utilities for executing single test files and directories of test specifications.
- tmux must be installed.
- Go 1.23.4+
go get github.com/SirMoM/tmux-tui-testing
A .ttt
file defines steps in this format:
# <name>
: Defines the name of the Test.% <rootProgram>
: Start a root / parent program. It is recommended to use a shell and define a prompt (e.g.% PS1="$ " sh
).> "<command>" <confirmationKey> <timeoutInMs>
: Send input to the shell (e.g.,> "echo Hello" enter 0
).- Confirmation Key Options are:
enter
: Sends anEnter
key presstab
: Sends aTab
key pressnone
: No key press is sent
- Confirmation Key Options are:
- Expected output is matched verbatim after each command.
A .ttt
test specification defines a sequence of terminal commands and expected outputs.
#Minimal Test
% PS1="" sh
> "echo 'Hello World'" enter 0
> "ls" enter 10
Hello World
ls
example_test.go minimal.ttt testfiles
More examples can be found in the examples/testfiles
directory.
You can run a single .ttt
test specification using:
ttt.RunTestSpec("path/to/test.ttt", t)
To execute all .ttt
test files within a directory:
ttt.RunTestSpecDir("path/to/tests", t)
To run the included example test suite:
go test ./...