specmem cov¶
Analyze the gap between specification acceptance criteria and existing tests.
Overview¶
The specmem cov command provides spec coverage analysis - measuring how well your acceptance criteria are covered by tests. It scans your spec files to extract acceptance criteria, scans test files to find test functions, and uses semantic matching to link them together.
Usage¶
# Show overall coverage summary
specmem cov
# Show detailed report for a feature
specmem cov report user-authentication
# Get test suggestions for uncovered criteria
specmem cov suggest user-authentication
# Generate coverage badge for README
specmem cov badge
# Export coverage data
specmem cov export --format json
specmem cov export --format markdown
Commands¶
specmem cov¶
Shows overall coverage summary with a table of all features.
$ specmem cov
๐ Spec Coverage Report โ
========================================
Overall: 374/463 criteria covered (80.8%)
Coverage by Feature
โโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโ
โ Feature โ Tested โ Total โ Coverage โ Gap โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ user-authentication โ 8 โ 12 โ 66.7% โ 33.3% โ ๏ธ โ
โ payment-processing โ 15 โ 15 โ 100.0% โ 0.0% โ
โ
โ notification-system โ 6 โ 10 โ 60.0% โ 40.0% โ ๏ธ โ
โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
specmem cov report [FEATURE]¶
Shows detailed coverage for a specific feature or all features.
$ specmem cov report user-authentication
user-authentication โ ๏ธ
Coverage: 8/12 (66.7%)
โ
AC 1.1: WHEN user provides valid credentials... โ tests/test_auth.py:45
โ
AC 1.2: WHEN user provides invalid credentials... โ tests/test_auth.py:67
โ ๏ธ AC 1.3: WHEN user fails login 5 times... โ NO TEST FOUND
โ ๏ธ AC 1.4: WHEN session inactive 30min... โ NO TEST FOUND
Options:
- --path, -p: Workspace path (default: current directory)
- --verbose, -v: Show detailed output
specmem cov suggest FEATURE¶
Get test suggestions for uncovered acceptance criteria.
$ specmem cov suggest user-authentication
๐ Test Suggestions for: user-authentication
==================================================
1. AC 1.3:
"WHEN user fails login 5 times THEN system SHALL lock account..."
Suggested test approach:
- Test file: tests/test_user_authentication.py
- Test name: test_user_fails_login_5_times
- What to verify:
โข Verify: the system SHALL lock account
2. AC 1.4:
"WHEN session inactive 30min THEN system SHALL expire session..."
Suggested test approach:
- Test file: tests/test_user_authentication.py
- Test name: test_session_inactive_30min
- What to verify:
โข Verify: the system SHALL expire session
๐ก Copy these suggestions to your agent to generate the actual tests.
specmem cov badge¶
Generate a coverage badge for your README.
$ specmem cov badge

# Save to file
$ specmem cov badge --output COVERAGE_BADGE.md
Badge colors: - ๐ด Red: Coverage < 50% - ๐ก Yellow: Coverage 50-80% - ๐ข Green: Coverage > 80%
specmem cov export¶
Export coverage data in JSON or Markdown format.
# Export as JSON
$ specmem cov export --format json > coverage.json
# Export as Markdown
$ specmem cov export --format markdown > COVERAGE.md
# Export to specific file
$ specmem cov export --format json --output coverage-report.json
How It Works¶
-
Extract Criteria: Parses
requirements.mdfiles in.kiro/specs/to extract numbered acceptance criteria in EARS format. -
Scan Tests: Scans test files (pytest, jest, vitest, playwright, mocha) to extract test functions with their docstrings.
-
Match: Uses two matching strategies:
- Explicit links: Tests with
Validates: X.Yin docstrings get confidence 1.0 -
Semantic matching: Text similarity between criterion and test name/docstring
-
Report: Criteria with confidence โฅ 0.5 are considered "covered".
Linking Tests to Criteria¶
For best results, add explicit links in your test docstrings:
def test_account_lockout_after_failed_attempts():
"""Test that accounts are locked after 5 failed login attempts.
Validates: 1.3
"""
# Test implementation
Python API¶
from specmem import SpecMemClient
client = SpecMemClient()
# Get overall coverage
result = client.get_coverage()
print(f"Coverage: {result.coverage_percentage:.1f}%")
# Get coverage for specific feature
result = client.get_coverage("user-authentication")
# Get test suggestions
suggestions = client.get_coverage_suggestions("user-authentication")
for s in suggestions:
print(f"- {s.criterion.number}: {s.suggested_name}")
# Generate badge
badge = client.get_coverage_badge()
See Also¶
- specmem validate - Validate spec quality
- specmem impact - Analyze impact of changes