Skip to main content
RTK follows a Test-Driven Development (TDD) approach with multiple layers of testing to ensure correctness, performance, and maintainability.

Testing Strategy

Test Pyramid

RTK uses a three-tier testing approach:

Test Coverage

  • Unit tests: 105+ tests across 25+ modules
  • Smoke tests: 69 assertions covering all commands
  • TDD workflow: Red-Green-Refactor mandatory for all new code
From CLAUDE.md: “All code follows Red-Green-Refactor. See .claude/skills/rtk-tdd/ for the full workflow and Rust-idiomatic patterns.”

TDD Workflow

Red-Green-Refactor Cycle

1

RED: Write a failing test

Start by writing a test for the functionality you want to implement:
Run the test - it should fail because the function doesn’t exist yet:
2

GREEN: Implement minimal code to pass

Write the simplest code that makes the test pass:
Run the test again - it should now pass:
3

REFACTOR: Improve the code

Refactor for clarity, performance, and maintainability:
Run tests again to ensure refactoring didn’t break anything:

Dominant Pattern

From CLAUDE.md (line 403):
Dominant pattern: raw string input → filter function → assert output contains/excludes
Example:

Unit Tests

Test Organization

Unit tests are embedded in each module:

Running Unit Tests

Test Fixtures

For complex outputs, use fixture files:
Fixture location: tests/fixtures/<cmd>_raw.txt

Integration Tests

Command Execution Tests

Integration tests execute real commands:
Integration tests require the RTK binary to be built first: cargo build

Smoke Tests

scripts/test-all.sh

Smoke tests validate all commands on a real system:

Running Smoke Tests

Smoke tests are run manually before releases. They require RTK to be installed system-wide.

Performance Benchmarks

Startup Time

Verify <10ms startup time requirement:
Acceptable: RTK overhead <10ms (typically 5-15ms)

Memory Usage

Target: <5MB resident memory

Token Savings Verification

Verify token savings in tests:

Manual Testing Requirements

For Filter Changes

From CLAUDE.md (lines 477-481): Manual testing is REQUIRED for filter changes:
1

Test with real command

Inspect output, verify condensed correctly
2

Verify critical info preserved

Check that essential information is retained:
  • Commit hashes for git log
  • Error messages for linters
  • File names for file operations
3

Check format is readable

Output should be human-readable and consistently formatted
4

Verify exit code

For Hook Changes

Test in real Claude Code session:
  1. Create test Claude Code session
  2. Type raw command (e.g., git status)
  3. Verify hook rewrites to rtk git status
  4. Check output is correct

For Performance Changes

1

Benchmark baseline

2

Make changes and rebuild

3

Benchmark again

4

Compare results

Startup time should remain <10ms

Cross-Platform Testing

From CLAUDE.md (lines 494-497):
  • macOS (zsh): Test locally
  • Linux (bash): Use Docker
  • Windows (PowerShell): Trust CI/CD pipeline or test manually
Anti-pattern: Running only automated tests (cargo test, cargo clippy) without actually executing rtk <cmd> and inspecting output.

Test Commands Reference

Test Writing Guidelines

1. Test Names Should Be Descriptive

2. Use Assert Messages

3. Test Edge Cases

4. Verify Token Savings

All filter tests should verify ≥60% token savings:

Untested Modules Backlog

From CLAUDE.md (line 398):
See .claude/skills/rtk-tdd/references/testing-patterns.md for RTK-specific patterns and untested module backlog.
Modules that may need additional test coverage:
  • Container commands (docker/podman)
  • GitHub CLI commands (gh)
  • Environment commands (env)
  • Some error handling paths

Next Steps