Write comprehensive failing tests following TDD red phase principles.
[Extended thinking: Generates failing tests that properly define expected behavior using test-automator agent.]
Use this skill when
- Starting the TDD red phase for new behavior
- You need failing tests that capture expected behavior
- You want edge case coverage before implementation
Do not use this skill when
- You are in the green or refactor phase
- You only need performance benchmarks
- Tests must run against production systems
Instructions
- Identify behaviors, constraints, and edge cases.
- Generate failing tests that define expected outcomes.
- Ensure failures are due to missing behavior, not setup errors.
- Document how to run tests and verify failures.
Safety
- Keep test data isolated and avoid production environments.
- Avoid flaky external dependencies in the red phase.
Role
Generate failing tests using Task tool with subagent_type="unit-testing::test-automator".
Prompt Template
"Generate comprehensive FAILING tests for: $ARGUMENTS
Core Requirements
Test Structure
- Framework-appropriate setup (Jest/pytest/JUnit/Go/RSpec)
- Arrange-Act-Assert pattern
- should_X_when_Y naming convention
- Isolated fixtures with no interdependencies
Behavior Coverage
- Happy path scenarios
- Edge cases (empty, null, boundary values)
- Error handling and exceptions
- Concurrent access (if applicable)
Failure Verification
- Tests MUST fail when run
- Failures for RIGHT reasons (not syntax/import errors)
- Meaningful diagnostic error messages
- No cascading failures
Test Categories
- Unit: Isolated component behavior
- Integration: Component interaction
- Contract: API/interface contracts
- Property: Mathematical invariants
Framework Patterns
JavaScript/TypeScript (Jest/Vitest)
- Mock dependencies with
vi.fn() or jest.fn()
- Use
@testing-library for React components
- Property tests with
fast-check
Python (pytest)
- Fixtures with appropriate scopes
- Parametrize for multiple test cases
- Hypothesis for property-based tests
Go
- Table-driven tests with subtests
t.Parallel() for parallel execution
- Use
testify/assert for cleaner assertions
Ruby (RSpec)
let for lazy loading, let! for eager
- Contexts for different scenarios
- Shared examples for common behavior
Quality Checklist
- Readable test names documenting intent
- One behavior per test
- No implementation leakage
- Meaningful test data (not 'foo'/'bar')
- Tests serve as living documentation
Anti-Patterns to Avoid
- Tests passing immediately
- Testing implementation vs behavior
- Complex setup code
- Multiple responsibilities per test
- Brittle tests tied to specifics
Edge Case Categories
- Null/Empty: undefined, null, empty string/array/object
- Boundaries: min/max values, single element, capacity limits
- Special Cases: Unicode, whitespace, special characters
- State: Invalid transitions, concurrent modifications
- Errors: Network failures, timeouts, permissions
Output Requirements
- Complete test files with imports
- Documentation of test purpose
- Commands to run and verify failures
- Metrics: test count, coverage areas
- Next steps for green phase"
Validation
After generation:
- Run tests - confirm they fail
- Verify helpful failure messages
- Check test independence
- Ensure comprehensive coverage
Example (Minimal)
// auth.service.test.ts
describe('AuthService', () => {
let authService: AuthService;
let mockUserRepo: jest.Mocked<UserRepository>;
beforeEach(() => {
mockUserRepo = { findByEmail: jest.fn() } as any;
authService = new AuthService(mockUserRepo);
});
it('should_return_token_when_valid_credentials', async () => {
const user = { id: '1', email: 'test@example.com', passwordHash: 'hashed' };
mockUserRepo.findByEmail.mockResolvedValue(user);
const result = await authService.authenticate('test@example.com', 'pass');
expect(result.success).toBe(true);
expect(result.token).toBeDefined();
});
it('should_fail_when_user_not_found', async () => {
mockUserRepo.findByEmail.mockResolvedValue(null);
const result = await authService.authenticate('none@example.com', 'pass');
expect(result.success).toBe(false);
expect(result.error).toBe('INVALID_CREDENTIALS');
});
});
Test requirements: $ARGUMENTS
1---2version: 4.1.0-fractal3name: tdd-workflows-tdd-red4description: Generate failing tests for the TDD red phase to define expected behavior and edge cases.5metadata:6 source: https://skillmd.com/skills/dokhacgiakhoa/tdd-workflows-tdd-red7---89Write comprehensive failing tests following TDD red phase principles.1011[Extended thinking: Generates failing tests that properly define expected behavior using test-automator agent.]1213## Use this skill when1415- Starting the TDD red phase for new behavior16- You need failing tests that capture expected behavior17- You want edge case coverage before implementation1819## Do not use this skill when2021- You are in the green or refactor phase22- You only need performance benchmarks23- Tests must run against production systems2425## Instructions26271. Identify behaviors, constraints, and edge cases.282. Generate failing tests that define expected outcomes.293. Ensure failures are due to missing behavior, not setup errors.304. Document how to run tests and verify failures.3132## Safety3334- Keep test data isolated and avoid production environments.35- Avoid flaky external dependencies in the red phase.3637## Role3839Generate failing tests using Task tool with subagent_type="unit-testing::test-automator".4041## Prompt Template4243"Generate comprehensive FAILING tests for: $ARGUMENTS4445## Core Requirements46471. **Test Structure**48 - Framework-appropriate setup (Jest/pytest/JUnit/Go/RSpec)49 - Arrange-Act-Assert pattern50 - should_X_when_Y naming convention51 - Isolated fixtures with no interdependencies52532. **Behavior Coverage**54 - Happy path scenarios55 - Edge cases (empty, null, boundary values)56 - Error handling and exceptions57 - Concurrent access (if applicable)58593. **Failure Verification**60 - Tests MUST fail when run61 - Failures for RIGHT reasons (not syntax/import errors)62 - Meaningful diagnostic error messages63 - No cascading failures64654. **Test Categories**66 - Unit: Isolated component behavior67 - Integration: Component interaction68 - Contract: API/interface contracts69 - Property: Mathematical invariants7071## Framework Patterns7273**JavaScript/TypeScript (Jest/Vitest)**74- Mock dependencies with `vi.fn()` or `jest.fn()`75- Use `@testing-library` for React components76- Property tests with `fast-check`7778**Python (pytest)**79- Fixtures with appropriate scopes80- Parametrize for multiple test cases81- Hypothesis for property-based tests8283**Go**84- Table-driven tests with subtests85- `t.Parallel()` for parallel execution86- Use `testify/assert` for cleaner assertions8788**Ruby (RSpec)**89- `let` for lazy loading, `let!` for eager90- Contexts for different scenarios91- Shared examples for common behavior9293## Quality Checklist9495- Readable test names documenting intent96- One behavior per test97- No implementation leakage98- Meaningful test data (not 'foo'/'bar')99- Tests serve as living documentation100101## Anti-Patterns to Avoid102103- Tests passing immediately104- Testing implementation vs behavior105- Complex setup code106- Multiple responsibilities per test107- Brittle tests tied to specifics108109## Edge Case Categories110111- **Null/Empty**: undefined, null, empty string/array/object112- **Boundaries**: min/max values, single element, capacity limits113- **Special Cases**: Unicode, whitespace, special characters114- **State**: Invalid transitions, concurrent modifications115- **Errors**: Network failures, timeouts, permissions116117## Output Requirements118119- Complete test files with imports120- Documentation of test purpose121- Commands to run and verify failures122- Metrics: test count, coverage areas123- Next steps for green phase"124125## Validation126127After generation:1281. Run tests - confirm they fail1292. Verify helpful failure messages1303. Check test independence1314. Ensure comprehensive coverage132133## Example (Minimal)134135```typescript136// auth.service.test.ts137describe('AuthService', () => {138 let authService: AuthService;139 let mockUserRepo: jest.Mocked<UserRepository>;140141 beforeEach(() => {142 mockUserRepo = { findByEmail: jest.fn() } as any;143 authService = new AuthService(mockUserRepo);144 });145146 it('should_return_token_when_valid_credentials', async () => {147 const user = { id: '1', email: 'test@example.com', passwordHash: 'hashed' };148 mockUserRepo.findByEmail.mockResolvedValue(user);149150 const result = await authService.authenticate('test@example.com', 'pass');151152 expect(result.success).toBe(true);153 expect(result.token).toBeDefined();154 });155156 it('should_fail_when_user_not_found', async () => {157 mockUserRepo.findByEmail.mockResolvedValue(null);158159 const result = await authService.authenticate('none@example.com', 'pass');160161 expect(result.success).toBe(false);162 expect(result.error).toBe('INVALID_CREDENTIALS');163 });164});165```166167Test requirements: $ARGUMENTS