- Overview
- Key Features
- Installation
- Configuration
- Detailed Component Breakdown
- Advanced Usage
- Error Handling
- Performance Considerations
- Future Roadmap
An AI-powered code testing framework that analyzes, tests, and provides feedback on code based on specifications.
- Static code analysis using AST
- Automatic test case generation
- AI-powered edge case analysis
- Comprehensive test execution
- Detailed feedback and reporting
| Model | Provider | Support Level | Capabilities |
|---|---|---|---|
| GPT-4 | OpenAI | Full | Advanced analysis, comprehensive feedback |
| GPT-3.5 Turbo | OpenAI | Basic | Standard analysis, limited depth |
| Claude 3 Opus | Anthropic | Experimental | Advanced reasoning, nuanced feedback |
pip install code-testing-agentgit clone https://github.com/yourusername/code-testing-agent.git
cd code-testing-agent
pip install -e .importosfromdotenvimportload_dotenv# Load API keys from .env fileload_dotenv()
# Set OpenAI API keyos.environ['OPENAI_API_KEY'] ='your-openai-api-key'fromcode_testing_agentimportCodeTester# Initialize with API keytester=CodeTester(llm_api_key='your-api-key')CodeSpec(
description: str, # Human-readable description of the codeexpected_inputs: Dict[str, type], # Input type constraintsexpected_outputs: Dict[str, type], # Output type constraintsexample_test_cases: List[Dict[str, Any]], # Predefined test casesconstraints: Optional[List[str]] =None# Additional code constraints
)spec=CodeSpec(
description="Calculate average of a list of numbers",
expected_inputs={"numbers": list},
expected_outputs={"result": float},
example_test_cases=[
{
"inputs": {"numbers": [1, 2, 3, 4, 5]},
"expected": 3.0
}
],
constraints=[
"Input list must contain only numbers",
"Handles empty list by returning 0"
]
)- Abstract Syntax Tree (AST) parsing
- Syntax structure evaluation
- Potential issue detection
- Code complexity assessment
- Mutable default arguments
- Infinite loops
- Redundant comparisons
- Exception handling anti-patterns
fromcode_testing_agentimportCodeTester# Configure with custom OpenAI modeltester=CodeTester(
llm_api_key='your-key',
model='gpt-4', # Specify modeltemperature=0.7, # Adjust creativitymax_tokens=500# Limit response length
)fromcode_testing_agent.analyzersimportCodeAnalyzerclassCustomCodeAnalyzer(CodeAnalyzer):
defadditional_checks(self, tree: ast.AST):
# Add custom static analysis rulespassCodeTestingError: Base exception
ValidationError: Code validation failures
TestExecutionError: Test runtime errors
try:
result=tester.test_code(code, spec)
exceptValidationErrorase:
print(f"Code validation failed: {e}")
exceptTestExecutionErrorase:
print(f"Test execution error: {e}")- Caching analysis results
- Configurable recursion limits
- Timeout mechanisms for long-running tests
- Selective test case execution
- Multi-language support
- More advanced AI models
- Enhanced test case generation
- Performance profiling
- Integration with CI/CD pipelines