smart-test
Skill0 starsChanged 6 months agoMITView on GitHub
Intelligently run and fix tests based on code changes
In this repositoryOne other file it gives its agents.
- quick-commitSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Test framework installed (Jest, pytest, JUnit, etc.)
- Distinctive: line 121
Solution: Use targeted test runs:
- Distinctive: line 134
Solution: Read the actual error message:
- Distinctive: line 147
Only modify test if requirements changed
- Distinctive: line 153
Solution: Add tests for:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Smart Test
Automatically identify and run relevant tests based on your code changes, then fix failures.
When to Use
✅ Use this skill when:
- You've made code changes and need to verify they work
- You want to run only relevant tests (not the full suite)
- Tests are failing and you need to fix them
- You want to improve test coverage
❌ Do NOT use when:
- Writing tests from scratch (use test-driven-development instead)
- Debugging production issues (use systematic-debugging)
Prerequisites
- Test framework installed (Jest, pytest, JUnit, etc.)
- Existing test suite
- Code changes ready to test
Quick Start
# Find tests related to changed files
git diff --name-only | grep -E "\.(js|ts|py|java)$" | while read f; do
echo "Related test: ${f%.*}.test.${f##*.}"
done
# Run relevant tests
npm test -- --findRelatedTests $(git diff --name-only)Instructions
Step 1: Identify Changed Files
# What files changed?
git diff --name-only HEAD~1
# Or for staged changes
git diff --cached --name-onlyStep 2: Map to Test Files
| Source File | Test File Pattern |
src/auth/login.js | tests/auth/login.test.js |
lib/utils.py | tests/test_utils.py |
src/User.java | test/UserTest.java |
Common patterns:
# JavaScript/TypeScript
echo "src/components/Button.tsx" | sed 's|src/|tests/|;s|\.tsx$|.test.tsx|'
# Python
echo "lib/utils.py" | sed 's|lib/|tests/test_|;s|\.py$||'
# Java
echo "src/main/User.java" | sed 's|src/main/|src/test/|;s|\.java$|Test.java|'Step 3: Run Targeted Tests
# Jest (JavaScript)
npx jest --findRelatedTests src/auth/login.js
# pytest (Python)
pytest tests/test_utils.py -v
# Gradle (Java)
./gradlew test --tests "*UserTest*"
# All changed files
git diff --name-only | xargs -I {} sh -c 'echo "Testing: {}" && npm test -- --findRelatedTests {}'Step 4: Analyze Failures
# Run with verbose output
npm test -- --verbose 2>&1 | tee test-output.log
# Show only failures
grep -A 5 "FAIL" test-output.logStep 5: Fix and Re-run
# Fix the code or test
vim src/auth/login.js
# Re-run failing test
npm test -- --testPathPattern="login" --watchPitfalls
⚠️ Common Mistakes:
1. Running all tests every time
Problem: Full test suite takes too long
Solution: Use targeted test runs:
# Instead of
npm test # Runs everything
# Do this
npm test -- --findRelatedTests src/changed-file.js2. Ignoring test output
Problem: Just checking pass/fail, not reading errors
Solution: Read the actual error message:
# Show full error details
npm test -- --verbose 2>&1 | grep -B 5 -A 10 "Error"3. Fixing tests to pass (not fixing code)
Problem: Changing tests to match broken behavior
Solution:
- Understand what the test verifies
- Fix the source code, not the test
- Only modify test if requirements changed
4. Not testing edge cases
Problem: Tests pass with happy path only
Solution: Add tests for:
- Null/undefined inputs
- Empty arrays/strings
- Boundary values
- Error conditions
Verification
After running tests:
- All tests pass
npm test 2>&1 | tail -5 # Should show: Tests: X passed, X total - Coverage is maintained
npm test -- --coverage # Check coverage didn't decrease - No skipped tests
grep -r "skip\|xit\|xdescribe" tests/ # Should be empty
Examples
Example 1: JavaScript with Jest
# Changed file
git diff --name-only
# src/utils/validation.js
# Run related tests
npx jest --findRelatedTests src/utils/validation.js
# Output:
# PASS tests/utils/validation.test.js
# validateEmail
# ✓ should validate correct email
# ✓ should reject invalid email
# ✓ should handle empty string
#
# Test Suites: 1 passed, 1 total
# Tests: 3 passed, 3 totalExample 2: Python with pytest
# Changed file
git diff --name-only
# lib/database.py
# Run related tests
pytest tests/test_database.py -v
# Output:
# tests/test_database.py::TestDatabase::test_connection PASSED
# tests/test_database.py::TestDatabase::test_query PASSED
# tests/test_database.py::TestDatabase::test_transaction PASSEDExample 3: Fixing a Failing Test
# Run tests
npm test 2>&1 | grep "FAIL"
# FAIL tests/auth/login.test.js
# See the error
npm test -- --testPathPattern="login" 2>&1 | grep -A 10 "Error"
# Expected: { success: true }
# Received: { success: false, error: "Invalid credentials" }
# Fix the code
vim src/auth/login.js
# Re-run
npm test -- --testPathPattern="login"
# PASS tests/auth/login.test.jsAdvanced: Watch Mode
# Jest watch mode - re-runs on file changes
npm test -- --watch
# pytest watch mode (with pytest-watch)
ptw tests/test_utils.py
# Run only failed tests
npm test -- --onlyFailuresReferences
- Jest Documentation
- pytest Documentation
- Testing Library
- Test Driven Development
Part of Awesome AI Agent Skills
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

