From harness-claude
Guides Test-Driven Development (TDD) via red-green-refactor cycle and test-first approach for new features, bug fixes, API design, and refactoring with safety nets. Uses TypeScript/Vitest examples.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Drive design through tests using red-green-refactor cycle and test-first discipline
Guides strict Test-Driven Development (Red-Green-Refactor): write failing tests for normal/edge/error cases, minimal code to pass, refactor with checklists. Includes TypeScript example.
Enforces strict Test-Driven Development (TDD) for features and bugfixes: write failing test first, verify failure, minimal code to pass, refactor. No production code without failing test.
Share bugs, ideas, or general feedback.
Drive design through tests using red-green-refactor cycle and test-first discipline
describe('PasswordValidator', () => {
it('rejects passwords shorter than 8 characters', () => {
const result = validatePassword('short');
expect(result.valid).toBe(false);
expect(result.errors).toContain('Password must be at least 8 characters');
});
});
Run the test — it should fail (function does not exist or returns wrong value).
function validatePassword(password: string): ValidationResult {
const errors: string[] = [];
if (password.length < 8) {
errors.push('Password must be at least 8 characters');
}
return { valid: errors.length === 0, errors };
}
Run the test — it should pass.
// Extract rules into a composable structure
const rules: PasswordRule[] = [
{ test: (p) => p.length >= 8, message: 'Password must be at least 8 characters' },
{ test: (p) => /[A-Z]/.test(p), message: 'Password must contain an uppercase letter' },
];
function validatePassword(password: string): ValidationResult {
const errors = rules.filter((r) => !r.test(password)).map((r) => r.message);
return { valid: errors.length === 0, errors };
}
Run all tests — everything should still pass.
it('rejects passwords without uppercase letters', () => {
const result = validatePassword('lowercase123');
expect(result.valid).toBe(false);
expect(result.errors).toContain('Password must contain an uppercase letter');
});
it('accepts valid passwords', () => {
const result = validatePassword('ValidPass123!');
expect(result.valid).toBe(true);
expect(result.errors).toHaveLength(0);
});
vitest --watch
Tests re-run on every file save, showing red/green status immediately.
// First: test the public function
it('creates an order with total', async () => {
const order = await createOrder({ items: [{ sku: 'A', qty: 2, price: 10 }] });
expect(order.total).toBe(20);
});
// Then: test edge cases
it('applies bulk discount for qty > 10', async () => {
/* ... */
});
it('throws for empty items array', async () => {
/* ... */
});
// Tests serve as living documentation
describe('ShippingCalculator', () => {
it('charges flat $5 for orders under $50', () => {
/* ... */
});
it('provides free shipping for orders over $50', () => {
/* ... */
});
it('uses express rate when expedited shipping is selected', () => {
/* ... */
});
it('throws for negative order totals', () => {
/* ... */
});
});
TDD is a design technique that uses tests to drive the shape of the code. The core discipline is: never write production code without a failing test that demands it.
The three rules of TDD:
Benefits of TDD:
When TDD works best:
When TDD is harder:
Common TDD mistakes:
Trade-offs: