Skill: Run Tests
When to Use This Skill
This skill activates when you need to:
- •Run tests in an already-configured project
- •Execute tests with specific options (coverage, verbose, specific files)
- •Run tests in CI/CD or locally
- •Understand test execution commands for this project
Prerequisites
This skill assumes tests are already configured. If not, use the pytest-setup or jest-setup skill first.
Step-by-Step Workflow
Step 1: Detect Test Framework and Command
Check for configured test command:
Look in project configuration files:
- •
package.json→scripts.test - •
pyproject.toml→[tool.pytest]or custom scripts - •
Makefile→testtarget - •
.github/workflows/→ CI test commands - •
tox.ini→ test commands
If {{test_command}} is defined:
{{test_command}}
Step 2: Run Tests by Tech Stack
Python (pytest)
Basic test run:
pytest
Verbose output:
pytest -v
With coverage:
pytest --cov=src --cov-report=html --cov-report=term
Specific file:
pytest tests/test_example.py
Specific test:
pytest tests/test_example.py::test_function_name
Pattern matching:
pytest -k "test_user" # Run tests matching pattern
Markers:
pytest -m "not slow" # Skip slow tests pytest -m "integration" # Only integration tests
Parallel execution:
pytest -n auto # Requires pytest-xdist
Stop on first failure:
pytest -x
Show print output:
pytest -s
JavaScript/TypeScript (Jest)
Basic test run:
npm test # or yarn test
Watch mode:
npm test -- --watch
Coverage:
npm test -- --coverage
Specific file:
npm test -- tests/example.test.js
Pattern matching:
npm test -- --testNamePattern="user"
Update snapshots:
npm test -- --updateSnapshot
Verbose:
npm test -- --verbose
JavaScript/TypeScript (Vitest)
Run tests:
npm run test # or vitest
Watch mode:
vitest --watch
Coverage:
vitest --coverage
UI mode:
vitest --ui
Go
Run all tests:
go test ./...
Verbose:
go test -v ./...
Coverage:
go test -cover ./... go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out
Specific package:
go test ./pkg/mypackage
Run specific test:
go test -run TestFunctionName
Parallel:
go test -parallel 4 ./...
Benchmarks:
go test -bench=. ./...
Rust
Run all tests:
cargo test
Verbose:
cargo test -- --nocapture
Specific test:
cargo test test_name
Documentation tests:
cargo test --doc
Integration tests:
cargo test --test integration_test_name
Ruby (RSpec)
Run all tests:
rspec
Specific file:
rspec spec/models/user_spec.rb
Specific test:
rspec spec/models/user_spec.rb:42
Format:
rspec --format documentation
Java (Maven)
Run tests:
mvn test
Skip tests:
mvn install -DskipTests
Specific test:
mvn test -Dtest=TestClassName
Java (Gradle)
Run tests:
./gradlew test
Continuous:
./gradlew test --continuous
Specific test:
./gradlew test --tests TestClassName
Step 3: Common Test Execution Patterns
Run tests before commit:
# Add to pre-commit hook
git add -A
{{test_command}}
git commit -m "message"
Run tests with timeout:
# Python pytest --timeout=300 # JavaScript npm test -- --testTimeout=5000
Run failed tests only:
# Python pytest --lf # last failed pytest --ff # failed first # Jest npm test -- --onlyFailures
Generate coverage report:
# Python pytest --cov=src --cov-report=html open htmlcov/index.html # JavaScript npm test -- --coverage open coverage/lcov-report/index.html
Common Issues and Solutions
Issue: Tests not found or not running
Solutions:
- •Verify you're in the project root directory
- •Check test file naming conventions match framework expectations
- •Ensure test dependencies are installed:
pip install -r requirements.txtornpm install - •Check test configuration files (pytest.ini, jest.config.js)
Issue: Tests failing locally but pass in CI
Solutions:
- •Check environment variables (
.envfiles) - •Verify Python/Node version matches CI
- •Clear caches:
pytest --cache-clearorjest --clearCache - •Check for local-only fixtures or data
- •Review CI logs for differences in test execution
Issue: Tests timing out
Solutions:
- •Increase timeout:
pytest --timeout=600or jest testTimeout - •Check for infinite loops or blocking operations
- •Use async/await properly in async tests
- •Mock external API calls
- •Use fixtures to avoid expensive setup
Issue: Import/module errors
Solutions:
- •Install in development mode:
pip install -e .ornpm install - •Check PYTHONPATH or NODE_PATH
- •Verify package.json "type" field for ES modules
- •Check tsconfig.json paths configuration
Issue: Coverage not accurate
Solutions:
- •Ensure all source files are included in coverage config
- •Check .coveragerc or jest.config.js coverage settings
- •Run with coverage flags:
--cov=srcor--coverage - •Clear coverage cache and re-run
Success Criteria
- •✅ Tests execute without errors
- •✅ Test results are displayed clearly
- •✅ Failed tests show helpful error messages
- •✅ Coverage reports generated (if requested)
- •✅ Test execution time is reasonable
Quick Reference
Common Commands by Framework
| Framework | Run Tests | Coverage | Specific Test |
|---|---|---|---|
| pytest | pytest -v | pytest --cov=src | pytest tests/test_file.py::test_name |
| Jest | npm test | npm test -- --coverage | npm test -- file.test.js |
| Vitest | vitest | vitest --coverage | vitest file.test.ts |
| Go | go test ./... | go test -cover ./... | go test -run TestName |
| Rust | cargo test | cargo tarpaulin | cargo test test_name |
| RSpec | rspec | rspec --coverage | rspec spec/file_spec.rb:42 |
Related Skills
- •pytest-setup - Set up pytest from scratch
- •debug-test-failures - Debug failing tests
- •ci-pipeline - Configure CI/CD test execution