create-sparc
Version:
NPX package to scaffold new projects with SPARC methodology structure
138 lines (110 loc) • 4.92 kB
Markdown
# Test-Driven Development Guidelines for aiGI
## Core TDD Principles
### Red-Green-Refactor Cycle
1. **Red**: Write a failing test that defines the expected behavior
2. **Green**: Write the minimal implementation code to make the test pass
3. **Refactor**: Improve the code while keeping tests passing
### Test First Approach
- Write tests before implementing features or fixes
- Use tests to guide implementation decisions
- Let failing tests drive the development process
### Incremental Development
- Add functionality in small, testable increments
- Build complex features through a series of simple, tested steps
- Maintain a working system at all times
## Best Practices for Writing Tests
### Test Structure
- Follow the Arrange-Act-Assert (AAA) pattern:
- **Arrange**: Set up test prerequisites and inputs
- **Act**: Execute the code being tested
- **Assert**: Verify the expected outcomes
- Keep tests focused on a single behavior or feature
- Use descriptive test names that explain what is being tested
### Test Coverage
- Aim for high code coverage (>80% for critical components)
- Focus on testing behavior rather than implementation details
- Include tests for edge cases, error conditions, and boundary values
- Test both positive and negative scenarios
### Test Independence
- Ensure tests can run in any order
- Avoid dependencies between tests
- Reset state between tests to prevent cross-test contamination
- Use setup and teardown methods appropriately
### Test Readability
- Write clear, self-documenting tests
- Use descriptive variable names and assertions
- Include comments explaining complex test scenarios
- Structure tests to tell a story about the code's behavior
## Integration with MCP for Error Resolution
### Using MCP Tools for Test Enhancement
- Leverage MCP tools to generate test cases based on specifications
- Use MCP for identifying edge cases and boundary conditions
- Apply MCP analysis to improve test coverage
- Utilize MCP for validating test quality and completeness
### Error Resolution Workflow
1. When a test fails, use MCP to analyze the failure
2. Generate potential fixes based on the analysis
3. Apply fixes incrementally, verifying each step
4. Document the resolution process for future reference
### Continuous Improvement
- Use MCP to identify patterns in test failures
- Apply learned patterns to prevent similar issues
- Continuously refine testing strategies based on MCP insights
- Build a knowledge base of common issues and resolutions
## Self-Reflection and Improvement
### Test Quality Metrics
- Regularly review test coverage metrics
- Analyze test execution times and optimize slow tests
- Track test reliability and address flaky tests
- Measure and improve test maintainability
### Retrospective Analysis
- Periodically review testing practices and outcomes
- Identify areas for improvement in test design and implementation
- Learn from test failures and successes
- Adapt testing strategies based on project evolution
### Knowledge Sharing
- Document testing patterns and best practices
- Share insights and lessons learned with the team
- Create reusable test utilities and frameworks
- Establish a culture of testing excellence
## Declarative Testing Approaches
### Behavior-Driven Development Integration
- Express tests in terms of expected behaviors
- Use given-when-then format for test scenarios
- Focus on business value and user requirements
- Bridge the gap between technical tests and business requirements
### Property-Based Testing
- Define properties that should hold true for all inputs
- Generate test cases automatically based on properties
- Discover edge cases through randomized testing
- Complement example-based tests with property-based tests
### Contract Testing
- Define explicit contracts between components
- Test that components adhere to their contracts
- Ensure compatibility between interacting parts
- Facilitate independent development of components
## TDD Workflow in aiGI
1. **Specification Review**
- Analyze requirements to identify testable behaviors
- Break down features into testable units
- Define acceptance criteria as test scenarios
2. **Test Creation**
- Write failing tests that validate requirements
- Include edge cases and error conditions
- Structure tests for clarity and maintainability
3. **Implementation**
- Write minimal code to make tests pass
- Focus on functionality, not optimization
- Commit after each passing test
4. **Refactoring**
- Improve code structure and readability
- Eliminate duplication and technical debt
- Maintain test coverage during refactoring
5. **Integration**
- Combine tested components
- Verify system behavior with integration tests
- Address any integration issues
6. **Reflection**
- Review test coverage and quality
- Identify areas for improvement
- Document lessons learned