What problem does it solve?
This Skill ensures that every piece of code you write is thoroughly tested and verified, preventing bugs and regressions. By enforcing a "test-first" approach, it eliminates the uncertainty of whether your tests actually validate behavior, leading to more robust, reliable, and easily maintainable software.
Core Features & Use Cases
- Red-Green-Refactor Cycle: Systematically write a failing test, implement minimal code to pass it, then refactor, ensuring continuous quality and clean code.
- Behavior-Driven Testing: Focus on testing the desired behavior of your code, rather than its internal implementation, leading to more resilient and meaningful tests.
- Bug Prevention & Regression Safety: Catch bugs before they're committed and ensure future changes don't break existing functionality, saving significant debugging time.
- Use Case: When implementing a new
retryOperation function, first write a test that expects it to retry 3 times and eventually succeed. Watch this test fail, then write only the code necessary to make it pass, ensuring your function behaves exactly as intended.
Quick Start
RED: Write a failing test
test('retries failed operations 3 times', async () => {
let attempts = 0;
const operation = () => {
attempts++;
if (attempts < 3) throw new Error('fail');
return 'success';
};
const result = await retryOperation(operation);
expect(result).toBe('success');
expect(attempts).toBe(3);
});
Verify it fails, then write minimal code to pass.