Test Writer Unit & Integration Skill
Overview
Generate unit and integration test scaffolds aligned to project conventions.
Usage
/test-writer-unit-integration
Identity
Role: QA Engineer
Objective: Generate robust, standardized test files based on the project's testing framework (Jest/Vitest/Playwright).
Context
You are generating tests for existing source code or as part of a TDD flow. The project conventions (naming, location) must be respected.
Strategies
Strategy A: Unit Tests ("Isolated")
Use when: Testing complex logic, pure functions, or single components.
Template:
- Imports: Import the System Under Test (SUT).
- Mocks: Mock ALL external dependencies (imports, DB calls, API clients).
- Structure:
describe('ClassName', () => {
beforeEach(() => { jest.clearAllMocks(); });
describe('methodName', () => {
it('should return result when condition met', () => { ... });
it('should throw error when invalid', () => { ... });
});
});
Strategy B: Integration Tests ("Real")
Use when: Testing database interactions, API endpoints, or component wiring.
Template:
Naming Conventions
- Files:
*.test.ts (Unit) vs *.spec.ts (E2E/Integration) - Check local patterns first.
- Suites: Top level
describe matches Class/Module name.
Workflow
- Analyze Source: Read the SUT (System Under Test) file.
- Determine Type: Unit or Integration?
- Draft: Create the test file using the appropriate strategy.
- Review: Ensure no imports are missing.
- Write: Save file.
Key Behaviors
- AAA Pattern: Always structure tests as Arrange, Act, Assert.
- No Flakes: Avoid
setTimeout, reliance on random execution order.
- Mocking: Use
jest.spyOn() or vi.spyOn() over overwriting functions.
Outputs
- Unit/integration test files aligned to project conventions.
Related Skills
/e2e-webapp-testing - E2E test guidance
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: test-writer-unit-integration3description: Generate standardized unit and integration tests Use when this capability is needed.4---56# Test Writer Unit & Integration Skill78## Overview910Generate unit and integration test scaffolds aligned to project conventions.1112## Usage1314```15/test-writer-unit-integration16```1718## Identity19**Role**: QA Engineer20**Objective**: Generate robust, standardized test files based on the project's testing framework (Jest/Vitest/Playwright).2122## Context23You are generating tests for existing source code or as part of a TDD flow. The project conventions (naming, location) must be respected.2425## Strategies2627### Strategy A: Unit Tests ("Isolated")28**Use when**: Testing complex logic, pure functions, or single components.29**Template**:30- **Imports**: Import the System Under Test (SUT).31- **Mocks**: Mock ALL external dependencies (imports, DB calls, API clients).32- **Structure**:33 ```typescript34 describe('ClassName', () => {35 beforeEach(() => { jest.clearAllMocks(); });36 describe('methodName', () => {37 it('should return result when condition met', () => { ... });38 it('should throw error when invalid', () => { ... });39 });40 });41 ```4243### Strategy B: Integration Tests ("Real")44**Use when**: Testing database interactions, API endpoints, or component wiring.45**Template**:46- **Setup**: `beforeAll` (connect DB), `afterAll` (disconnect/cleanup).47- **Dependencies**: Use REAL dependencies where possible (e.g., test database container), mock only external 3rd party APIs (Stripe, SendGrid).48- **Structure**:49 ```typescript50 describe('User API', () => {51 it('should create user in database', async () => { ... });52 });53 ```5455## Naming Conventions56- **Files**: `*.test.ts` (Unit) vs `*.spec.ts` (E2E/Integration) - *Check local patterns first*.57- **Suites**: Top level `describe` matches Class/Module name.5859## Workflow601. **Analyze Source**: Read the SUT (System Under Test) file.612. **Determine Type**: Unit or Integration?623. **Draft**: Create the test file using the appropriate strategy.634. **Review**: Ensure no imports are missing.645. **Write**: Save file.6566## Key Behaviors67- **AAA Pattern**: Always structure tests as **Arrange**, **Act**, **Assert**.68- **No Flakes**: Avoid `setTimeout`, reliance on random execution order.69- **Mocking**: Use `jest.spyOn()` or `vi.spyOn()` over overwriting functions.7071## Outputs7273- Unit/integration test files aligned to project conventions.7475## Related Skills7677- `/e2e-webapp-testing` - E2E test guidance7879---80> Converted and distributed by [TomeVault](https://tomevault.io/claim/etroxtaran) — claim your Tome and manage your conversions.81<!-- tomevault:4.0:skill_md:2026-04-16 -->