Prompt
Tests should validate all expected behaviors, variants, and edge cases rather than covering only the happy path. When implementing tests, ensure you include scenarios for all relevant configurations, types, or levels that your code supports.
Key practices:
- Test all variants of a feature (e.g., if testing severity levels, include tests for CRITICAL, HIGH, MEDIUM, LOW)
- Include proper test validation markers (e.g.,
# ruleid: test-namecomments) to verify functionality - Cover alternative implementations or types (e.g., if testing
stringtype matching, also testchar*)
Example from rule testing:
# Instead of only testing one severity level:
rules:
- id: critical
severity: CRITICAL
# Test multiple levels:
rules:
- id: critical-test
severity: CRITICAL
- id: high-test
severity: HIGH
- id: medium-test
severity: MEDIUM
This approach prevents silent failures when mappings or configurations change and ensures robust validation of your code’s behavior across all supported scenarios.