My5t3r10us/cesizen / .agents/skills/apex
apex
VerifiedSystematic implementation using APEX methodology (Analyze-Plan-Execute-eXamine) with optional parallel subagents, self-validation, and adversarial review. Use when implementing features, fixing bugs, or making code changes that benefit from structured workflow.
steps/step-07-tests.md
View on GitHub---
name: step-07-tests
description: Smart test analysis and creation - analyze patterns, create appropriate tests
prev_step: steps/step-04-validate.md
next_step: steps/step-08-run-tests.md
---
# Step 7: Tests (Analysis & Creation)
## MANDATORY EXECUTION RULES (READ FIRST):
- π NEVER create tests without analyzing existing patterns first
- π NEVER use wrong test type (unit when integration needed)
- β
ALWAYS analyze test infrastructure BEFORE writing
- β
ALWAYS follow existing test conventions exactly
- β
ALWAYS map tests to acceptance criteria
- π YOU ARE A TEST ENGINEER, not a code generator
- π¬ FOCUS on "What tests does this ACTUALLY need?"
- π« FORBIDDEN to ignore project test conventions
## EXECUTION PROTOCOLS:
- π― Analyze test infrastructure first
- πΎ Document test strategy (if save_mode)
- π Read similar tests before writing
- π« FORBIDDEN to write tests without reading examples
## CONTEXT BOUNDARIES:
- Implementation is complete and validated
- Test infrastructure exists (discovered in this step)
- Existing tests show conventions to follow
- Focus on creating RIGHT tests, not just tests
## YOUR TASK:
Analyze existing test patterns and create appropriate tests for the implementation.
---
<available_state>
From previous steps:
| Variable | Description |
|----------|-------------|
| `{task_description}` | What was implemented |
| `{task_id}` | Kebab-case identifier |
| `{auto_mode}` | Skip confirmations |
| `{save_mode}` | Save outputs to files |
| `{economy_mode}` | Lighter test analysis |
| `{output_dir}` | Path to output (if save_mode) |
| Files modified | From implementation |
| Acceptance criteria | From step-01 |
</available_state>
---
## EXECUTION SEQUENCE:
### 1. Initialize Save Output (if save_mode)
**If `{save_mode}` = true:**
```bash
bash {skill_dir}/scripts/update-progress.sh "{task_id}" "07" "tests" "in_progress"
```
Append analysis to `{output_dir}/07-tests.md` as you work.
### 2. Analyze Test Infrastructure
**2.1 Discover Framework**
```bash
cat package.json | grep -E "(jest|vitest|mocha|playwright|testing-library)"
```
**2.2 Find Config**
```bash
ls -la | grep -E "(jest|vitest|playwright)"
```
**2.3 Find Test Commands**
```bash
cat package.json | grep -A 5 '"scripts"' | grep -E "(test|spec)"
```
### 3. Analyze Existing Test Patterns
**If `{economy_mode}` = true:**
β Read 1 similar test file for patterns
**If `{economy_mode}` = false:**
β Read 2-3 similar test files
**Pattern Checklist:**
- [ ] describe/it vs test() syntax
- [ ] Setup/teardown patterns
- [ ] Mocking approach
- [ ] Assertion style
- [ ] Test data approach
### 4. Determine Test Strategy
| Implementation Type | Test Type |
|--------------------|-----------|
| API Route | Integration with supertest/fetch |
| Service/Logic | Integration with real deps |
| Utility Function | Unit with mocks |
| React Component | Component with testing-library |
| Full Feature | Integration + E2E |
### 5. Create Test Plan
```markdown
## Test Plan
**Framework:** {jest/vitest}
**Command:** `bun run test:unit` for web units, `bun run test:integration`
for API integration, or `cd mobile && npm test` for mobile units
### Tests to Create
**Integration:** `src/auth/register.test.ts`
- creates user with valid data (happy path)
- rejects invalid email (error case)
- handles auth failure (error case)
**Unit:** `src/utils/validation.test.ts`
- validates correct email
- rejects malformed email
```
**If `{auto_mode}` = false:**
```yaml
questions:
- header: "Tests"
question: "Review the test plan. Ready to create tests?"
options:
- label: "Create tests (Recommended)"
description: "Proceed with planned tests"
- label: "Add more tests"
description: "I want additional test cases"
- label: "Modify approach"
description: "Change the strategy"
- label: "Skip tests"
description: "Don't create tests"
multiSelect: false
```
### 6. Create Tests
**CRITICAL: Follow existing patterns EXACTLY**
1. Read similar test for reference
2. Create test file matching structure
3. Write tests following conventions
```typescript
import { describe, it, expect, beforeEach } from 'vitest'
describe('POST /api/auth/register', () => {
beforeEach(async () => {
await db.user.deleteMany()
})
it('creates user with valid data', async () => {
const response = await client.post('/api/auth/register', {
email: 'test@example.com',
password: 'SecurePass123!'
})
expect(response.status).toBe(201)
})
it('rejects invalid email', async () => {
const response = await client.post('/api/auth/register', {
email: 'invalid',
password: 'SecurePass123!'
})
expect(response.status).toBe(400)
})
})
```
### 7. Verify Tests
```bash
bun run type-check
```
List created tests:
```
**Tests Created:**
- `src/auth/register.test.ts` (3 tests)
- `src/utils/validation.test.ts` (2 tests)
```
### 8. Complete Save Output (if save_mode)
**If `{save_mode}` = true:**
Append to `{output_dir}/07-tests.md`:
```markdown
---
## Step Complete
**Status:** β Complete
**Tests created:** {count}
**Test files:** {list}
**Next:** step-08-run-tests.md
**Timestamp:** {ISO timestamp}
```
---
## SUCCESS METRICS:
β
Test infrastructure analyzed
β
Existing patterns studied
β
Appropriate test types chosen
β
Tests follow codebase conventions
β
Tests pass syntax check
β
All AC have corresponding tests
## FAILURE MODES:
β Writing tests without analyzing patterns
β Wrong test type for implementation
β Ignoring project conventions
β Tests don't match acceptance criteria
β Over-testing (testing implementation, not behavior)
β **CRITICAL**: Not using AskUserQuestion for approval
## TEST PROTOCOLS:
- Analyze BEFORE writing
- Follow existing patterns EXACTLY
- Test behavior, not implementation
- Map to acceptance criteria
- Create minimal, focused tests
---
## NEXT STEP:
After tests created, load `./step-08-run-tests.md`
<critical>
Remember: Create the RIGHT tests - analyze patterns first, then write!
</critical>
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why β repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" β or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself β your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |