Docs TUI Testing
TUI Testing
Snapshot, state and interaction testing for the terminal UI.
On this page
sipnab tests its TUI at three levels.
1. Snapshot tests (tests/tui_snapshot_test.rs)
Uses ratatui’s TestBackend to render views to an in-memory buffer, then insta for snapshot comparison.
Running
cargo test --features tui --test tui_snapshot_test
Updating snapshots
When rendering changes intentionally — --accept rewrites the .snap files in
place, and staging them in the same commit is what keeps CI comparing against
the new rendering:
# Run all of these, in order.
cargo insta test --features tui --accept
git add tests/snapshots/
Adding a new snapshot test
- Create a test function that renders to
TestBackend - Call
insta::assert_snapshot!(buffer_to_string(&terminal)) - Run
cargo insta test --acceptto create the initial snapshot - Commit the
.snapfile
2. State machine tests (tests/tui_state_test.rs)
Tests App state transitions without rendering. Uses App::new_test() and App::handle_key().
cargo test --features tui --test tui_state_test
3. PTY end-to-end tests (tests/tui_e2e_test.rs)
Drives the real binary inside a detached tmux session — not a bare PTY. sipnab’s TUI queries the terminal at startup (crossterm emits ESC[6n to read the cursor position), and a bare pseudo-terminal has no emulator behind it to answer, so the TUI aborts with cursor position could not be read. tmux is a terminal emulator: it answers the query, provides a real window size, and lets the test send keys and snapshot the screen with capture-pane. These are #[ignore] by default and need tmux on PATH.
cargo test --features tui --test tui_e2e_test -- --ignored
These tests are slower (~2s each) and may be flaky in CI.