---
roadcrew_template_name: "generate-test-cases.md"
roadcrew_template_type: "command"
execution_mode: "auto-execute"
roadcrew_template_version: "v1.0"
roadcrew_last_updated: "2025-10-25"
roadcrew_min_version: "1.5.0"
roadcrew_license: "See LICENSE file in .roadcrew folder"
roadcrew_copyright: "Copyright (c) 2025 North Star Holdings, LLC"
spdx_license_identifier: "LicenseRef-RoadcrewLicense-1.0"
---

# generate-test-cases

Automatically generate missing test cases from code to improve coverage.

## Usage

```bash
/generate-test-cases [--functions pattern] [--coverage-gaps] [--framework jest|pytest]
```

## What This Command Does

Generates comprehensive test cases including:
- **Happy Path Tests** - Normal use case scenarios
- **Edge Cases** - Boundary conditions, empty inputs, nulls
- **Error Cases** - Exception handling, invalid inputs
- **Integration Tests** - Component interactions

Generated tests:
- Follow project conventions (Jest for TypeScript)
- Use appropriate assertions
- Include setup/teardown
- Pass on first run (test-driven development)

## Implementation Workflow

### Phase 1: Gap Analysis
1. Analyze /analyze-test-coverage output for gaps
2. Identify untested functions
3. Parse function signatures and implementation

### Phase 2: Test Generation
1. For each untested function, generate test cases:
   - Happy path (primary use case)
   - Edge cases (null, empty, boundaries)
   - Error cases (invalid inputs, exceptions)
   - Integration scenarios

2. Generate Jest test file:
   ```typescript
   describe('functionName', () => {
     it('should handle happy path', () => {
       // Test implementation
     });

     it('should handle edge case: null input', () => {
       // Test implementation
     });

     it('should throw on invalid input', () => {
       // Test implementation
     });
   });
   ```

### Phase 3: Integration
- Add tests to project test suite
- Ensure all tests pass
- Update coverage metrics
- Generate coverage report

## Output Format

```bash
$ /generate-test-cases --coverage-gaps

🧪 Test Case Generator: roadcrew-internal

Coverage Gaps Found: 23 functions | Target: 35 test files

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📝 GENERATING TESTS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[+] github-issue-creator.test.ts
    - createIssuesInBatch() - 5 test cases
    - validateIssueLinks() - 4 test cases
    - formatIssueBody() - 3 test cases

[+] issue-parser.test.ts
    - parseIssue() - 6 test cases
    - validateStructure() - 4 test cases

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ TESTS GENERATED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Total Tests Generated: 47
Pass Rate: 100% (47/47 passing)
Coverage Improvement: 62% → 78%

Generated Files:
- tests/github-issue-creator.test.ts
- tests/issue-parser.test.ts
- tests/index.test.ts

📊 Full report: config/reports/test-generation-2025-10-29.md
🔗 Review tests: npm test
```

## Flags & Options

```bash
--functions pattern             # Generate tests for specific functions only
--coverage-gaps                 # Generate for all coverage gaps
--framework jest|pytest         # Test framework to use
--include-integration          # Include integration tests
--create-files                 # Actually create test files (vs dry-run)
```
