Intelligent test selection based on code changes. Maps source files to tests via import analysis, implements tiered testing (fast < 1 min, impacted < 5 min, full suite), and tracks test reliability. Use when running tests after code changes to optimize feedback loops and CI time.
View on GitHub.claude/skills/smart-test/SKILL.md
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/rysweet/amplihack/blob/main/.claude/skills/smart-test/SKILL.md -a claude-code --skill pre-commit-diagnosticInstallation paths:
.claude/skills/pre-commit-diagnostic/# Smart Test Selection Skill
## Purpose
Optimizes test execution by intelligently selecting which tests to run based on code changes. Instead of running the full test suite every time, this skill:
1. Maps code changes to affected test files using import dependency analysis
2. Provides tiered testing strategies for different feedback loop needs
3. Tracks test reliability to prioritize stable tests in fast runs
## When I Activate
I automatically load when you mention:
- "run affected tests" or "run impacted tests"
- "smart test" or "intelligent testing"
- "which tests to run" or "test selection"
- "fast tests" or "quick tests"
- "tests for changes" or "tests for this PR"
## Core Concepts
### Test Tiers
**Tier 1: Fast Tests (< 1 minute)**
- Directly affected unit tests (imports changed file)
- High-reliability tests only (no flaky tests)
- Run on every save or pre-commit
- Command: `pytest -m "not slow and not integration" [selected_tests]`
**Tier 2: Impacted Tests (< 5 minutes)**
- All tests affected by changes (direct + transitive dependencies)
- Includes integration tests for changed modules
- Run before commit or on PR draft
- Command: `pytest [selected_tests]`
**Tier 3: Full Suite**
- Complete test suite
- Run on PR ready-for-review or CI
- Command: `pytest`
### Import Dependency Analysis
The skill builds a dependency graph by analyzing Python imports:
```
source_file.py
|
+-- Imported by: module_a.py, module_b.py
| |
| +-- Tested by: test_module_a.py, test_module_b.py
|
+-- Tested by: test_source_file.py (direct test)
```
**Direct Tests**: Files matching pattern `test_{module}.py` or `{module}_test.py`
**Indirect Tests**: Tests that import modules which import the changed file
### Reliability Tracking
Tests are scored on reliability (0.0 to 1.0):
- **1.0**: Always passes (stable)
- **0.5-0.9**: Occasional failures (investigate)
- **< 0.5**: Frequently fails (flaky - excluded from Tier 1)
Reliability is traIssues Found: