---
roadcrew_template_name: "write-tests.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"
---

# write-tests

<!-- Usage: /write-tests 159 -->

You are generating failing tests for GitHub issue implementation following TDD principles.

**Input:** GitHub Issue number (with plan-implementation output)

**Output:** 
- Jest/Playwright/pytest test files with failing tests (RED state)
- Test coverage report
- Mock/fixture requirements
- Ready for `/implement-issue` to make tests pass

**Key Principle:** All tests must FAIL initially. If tests pass, something is wrong.

---

## WORKFLOW

### 1. ANALYZE ACCEPTANCE CRITERIA & TECHNICAL DESIGN

```bash
/write-tests {{ISSUE_NUMBER}}
```

The command will:
- Fetch issue details from GitHub
- Read acceptance criteria
- Use plan-implementation output for test structure
- Identify test boundaries (unit/integration/E2E)

### 2. GENERATE TEST FILES

**For each test type:**

**Unit Tests** (Core logic in isolation)
```typescript
describe('issue-core-logic', () => {
  it('should accept valid input', () => {
    // Arrange
    const input = validTestData;
    // Act & Assert
    expect(processInput(input)).toBeDefined();
  });
  
  it('should reject invalid input', () => {
    const invalid = invalidTestData;
    expect(() => processInput(invalid)).toThrow();
  });
});
```

**Integration Tests** (Component interactions)
```typescript
describe('issue-integration', () => {
  it('should integrate with upstream module', async () => {
    const planOutput = generateMockPlanOutput();
    const result = await executeWorkflow(planOutput);
    expect(result).toMatchSnapshot();
  });
});
```

**E2E Tests** (Full workflow - if applicable)
```typescript
describe('issue-e2e', () => {
  it('should complete end-to-end workflow', async () => {
    const epicData = getMockEpicData();
    const result = await fullImplementationWorkflow(epicData);
    expect(result.status).toBe('complete');
  });
});
```

### 3. VERIFY RED STATE

```bash
npm test -- --testPathPattern=issue-159
```

**Expected output:**
```
FAIL  [Issue #159 Tests]
  ✕ should generate valid tests (2 ms)
  ✕ should support multiple frameworks (1 ms)
  ✕ should verify RED state
  
4 tests, 4 failed
```

**If tests PASS**, there's an implementation somewhere - refactor to make them fail.

### 4. PRESENT OUTPUTS

- Test files created: `scripts/__tests__/issue-159.test.ts`
- Test count: N tests, all failing
- Coverage report: What will be tested
- Fixtures needed: Mock data requirements
- Ready for implementation? Yes (RED state verified)

### 5. AUTO-PROCEED

Ready to `/implement-issue` to make these tests pass.

---

## SUPPORTED TEST FRAMEWORKS

- **Jest** (TypeScript/JavaScript) - Default for Roadcrew
- **Playwright** (End-to-end browser testing)
- **pytest** (Python)

---

## ACCEPTANCE CRITERIA

✅ Command accepts issue number
✅ Generates failing tests (RED state)
✅ Supports Jest, Playwright, pytest
✅ Verifies all tests fail before returning
✅ Creates test files in proper location
✅ Includes unit, integration, E2E tests
✅ Documents mock/fixture requirements
✅ Ready for `/implement-issue` integration

---

**Parent Epic:** #185 (Implement Pattern Framework Phase 2)
**Related:** #158 (plan-implementation), #160 (autopilot)

---

Done
