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/excludesExample:
Unit Tests
Test Organization
Unit tests are embedded in each module:Running Unit Tests
Test Fixtures
For complex outputs, use fixture files:tests/fixtures/<cmd>_raw.txt
Integration Tests
Command Execution Tests
Integration tests execute real commands: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:Memory Usage
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
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:- Create test Claude Code session
- Type raw command (e.g.,
git status) - Verify hook rewrites to
rtk git status - Check output is correct
For Performance Changes
1
Benchmark baseline
2
Make changes and rebuild
3
Benchmark again
4
Compare results
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
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
- Adding Commands - Implement new filters with TDD
- Architecture - Understand filter strategies
- Security - Security testing and review process
